text
stringlengths
54
60.6k
<commit_before>9497850a-2d3d-11e5-ab27-c82a142b6f9b<commit_msg>95186294-2d3d-11e5-acf2-c82a142b6f9b<commit_after>95186294-2d3d-11e5-acf2-c82a142b6f9b<|endoftext|>
<commit_before>6cc1fcb4-2fa5-11e5-b4e9-00012e3d3f12<commit_msg>6cc41f94-2fa5-11e5-a99b-00012e3d3f12<commit_after>6cc41f94-2fa5-11e5-a99b-00012e3d3f12<|endoftext|>
<commit_before>da92a51c-585a-11e5-bfde-6c40088e03e4<commit_msg>da99ab98-585a-11e5-bfe6-6c40088e03e4<commit_after>da99ab98-585a-11e5-bfe6-6c40088e03e4<|endoftext|>
<commit_before>42701070-2748-11e6-8e46-e0f84713e7b8<commit_msg>my cat is cute<commit_after>4283ff75-2748-11e6-abae-e0f84713e7b8<|endoftext|>
<commit_before>57ae2a82-2e4f-11e5-8070-28cfe91dbc4b<commit_msg>57ba73fa-2e4f-11e5-a5bb-28cfe91dbc4b<commit_after>57ba73fa-2e4f-11e5-a5bb-28cfe91dbc4b<|endoftext|>
<commit_before>22915b3e-2f67-11e5-b7a5-6c40088e03e4<commit_msg>229b0774-2f67-11e5-9d99-6c40088e03e4<commit_after>229b0774-2f67-11e5-9d99-6c40088e03e4<|endoftext|>
<commit_before>15123964-585b-11e5-9094-6c40088e03e4<commit_msg>151998c6-585b-11e5-b0df-6c40088e03e4<commit_after>151998c6-585b-11e5-b0df-6c40088e03e4<|endoftext|>
<commit_before>b86852f8-327f-11e5-bf6f-9cf387a8033e<commit_msg>b86f623a-327f-11e5-885a-9cf387a8033e<commit_after>b86f623a-327f-11e5-885a-9cf387a8033e<|endoftext|>
<commit_before>7246f223-2749-11e6-b573-e0f84713e7b8<commit_msg>bug fix<commit_after>725507eb-2749-11e6-972e-e0f84713e7b8<|endoftext|>
<commit_before>f2446ef0-585a-11e5-8df7-6c40088e03e4<commit_msg>f24af058-585a-11e5-9604-6c40088e03e4<commit_after>f24af058-585a-11e5-9604-6c40088e03e4<|endoftext|>
<commit_before>282cc522-2f67-11e5-bf0b-6c40088e03e4<commit_msg>28338092-2f67-11e5-bcfd-6c40088e03e4<commit_after>28338092-2f67-11e5-bcfd-6c40088e03e4<|endoftext|>
<commit_before>94663685-327f-11e5-be8c-9cf387a8033e<commit_msg>946bfe21-327f-11e5-821c-9cf387a8033e<commit_after>946bfe21-327f-11e5-821c-9cf387a8033e<|endoftext|>
<commit_before>// main.cpp #include "TextEdit.h" #include <windows.h> #include <uxtheme.h> #define APPCLASS TEXT( "GoodNewsEveryone" ) HINSTANCE theInstance = 0; HWND theEdit = 0; void OnSize( HWND hwnd ) { RECT rect; GetClientRect( hwnd, &rect ); MoveWindow( theEdit, 0, 0, rect.right, rect.bottom, TRUE ); } LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_CREATE: theEdit = CreateWindow( WC_TEXTEDIT, TEXT( "" ), WS_CHILD|WS_VISIBLE|WS_VSCROLL, 0, 0, 0, 0, hwnd, NULL, theInstance, NULL ); return theEdit ? 0 : -1; case WM_SIZE: OnSize( hwnd ); return 0; case WM_DESTROY: PostQuitMessage( 0 ); return 0; } return DefWindowProc( hwnd, msg, wParam, lParam ); } bool InitApp() { WNDCLASSEX wcx = { sizeof wcx }; wcx.lpfnWndProc = WndProc; wcx.hInstance = theInstance; wcx.hCursor = LoadCursor( NULL, IDC_ARROW ); wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wcx.hbrBackground = reinterpret_cast<HBRUSH>( COLOR_WINDOW + 1 ); wcx.lpszClassName = APPCLASS; return RegisterClassEx( &wcx ) ? true : false; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { theInstance = hInstance; BufferedPaintInit(); if ( !InitApp() || !RegisterTextEdit( hInstance ) ) return 0; HWND hwnd = CreateWindow( APPCLASS, TEXT( "Let's edit some shit, yeah?" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, theInstance, 0 ); ShowWindow( hwnd, nShowCmd ); MSG msg; while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage ( &msg ); } BufferedPaintUnInit(); return 0; } <commit_msg>Initialize COM<commit_after>// main.cpp #include "TextEdit.h" #include <windows.h> #include <uxtheme.h> #define APPCLASS TEXT( "GoodNewsEveryone" ) HINSTANCE theInstance = 0; HWND theEdit = 0; void OnSize( HWND hwnd ) { RECT rect; GetClientRect( hwnd, &rect ); MoveWindow( theEdit, 0, 0, rect.right, rect.bottom, TRUE ); } LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_CREATE: theEdit = CreateWindow( WC_TEXTEDIT, TEXT( "" ), WS_CHILD|WS_VISIBLE|WS_VSCROLL, 0, 0, 0, 0, hwnd, NULL, theInstance, NULL ); return theEdit ? 0 : -1; case WM_SIZE: OnSize( hwnd ); return 0; case WM_DESTROY: PostQuitMessage( 0 ); return 0; } return DefWindowProc( hwnd, msg, wParam, lParam ); } bool InitApp() { WNDCLASSEX wcx = { sizeof wcx }; wcx.lpfnWndProc = WndProc; wcx.hInstance = theInstance; wcx.hCursor = LoadCursor( NULL, IDC_ARROW ); wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wcx.hbrBackground = reinterpret_cast<HBRUSH>( COLOR_WINDOW + 1 ); wcx.lpszClassName = APPCLASS; return RegisterClassEx( &wcx ) ? true : false; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { theInstance = hInstance; CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); BufferedPaintInit(); if ( !InitApp() || !RegisterTextEdit( hInstance ) ) return 0; HWND hwnd = CreateWindow( APPCLASS, TEXT( "Let's edit some shit, yeah?" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, theInstance, 0 ); ShowWindow( hwnd, nShowCmd ); MSG msg; while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage ( &msg ); } BufferedPaintUnInit(); CoUninitialize(); return 0; } <|endoftext|>
<commit_before>ad0240f6-35ca-11e5-b6da-6c40088e03e4<commit_msg>ad09027e-35ca-11e5-a3c2-6c40088e03e4<commit_after>ad09027e-35ca-11e5-a3c2-6c40088e03e4<|endoftext|>
<commit_before>7e7919c5-2d15-11e5-af21-0401358ea401<commit_msg>7e7919c6-2d15-11e5-af21-0401358ea401<commit_after>7e7919c6-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>5b682b38-5216-11e5-8ddd-6c40088e03e4<commit_msg>5b6ecc4c-5216-11e5-aefa-6c40088e03e4<commit_after>5b6ecc4c-5216-11e5-aefa-6c40088e03e4<|endoftext|>
<commit_before>809e9240-2d15-11e5-af21-0401358ea401<commit_msg>809e9241-2d15-11e5-af21-0401358ea401<commit_after>809e9241-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>2a679cd8-2f67-11e5-8ca9-6c40088e03e4<commit_msg>2a6e5f6c-2f67-11e5-8df4-6c40088e03e4<commit_after>2a6e5f6c-2f67-11e5-8df4-6c40088e03e4<|endoftext|>
<commit_before>8a7a0cba-35ca-11e5-96e9-6c40088e03e4<commit_msg>8a808650-35ca-11e5-9364-6c40088e03e4<commit_after>8a808650-35ca-11e5-9364-6c40088e03e4<|endoftext|>
<commit_before>b493b76e-2e4f-11e5-a310-28cfe91dbc4b<commit_msg>b49ad4ae-2e4f-11e5-bc6a-28cfe91dbc4b<commit_after>b49ad4ae-2e4f-11e5-bc6a-28cfe91dbc4b<|endoftext|>
<commit_before>9f5460b5-2747-11e6-a51f-e0f84713e7b8<commit_msg>NO CHANGES<commit_after>9f5ec44f-2747-11e6-9ca7-e0f84713e7b8<|endoftext|>
<commit_before>6ef6b706-2fa5-11e5-9cfa-00012e3d3f12<commit_msg>6ef88bc6-2fa5-11e5-b7ea-00012e3d3f12<commit_after>6ef88bc6-2fa5-11e5-b7ea-00012e3d3f12<|endoftext|>
<commit_before>b2a1bf63-2e4f-11e5-8375-28cfe91dbc4b<commit_msg>b2a942a3-2e4f-11e5-ae9d-28cfe91dbc4b<commit_after>b2a942a3-2e4f-11e5-ae9d-28cfe91dbc4b<|endoftext|>
<commit_before>192b9eab-2748-11e6-9e3f-e0f84713e7b8<commit_msg>Introduced random NullPointerException bug<commit_after>1935f078-2748-11e6-a293-e0f84713e7b8<|endoftext|>
<commit_before>16f2dd21-2d3f-11e5-bbae-c82a142b6f9b<commit_msg>1775d07a-2d3f-11e5-9e70-c82a142b6f9b<commit_after>1775d07a-2d3f-11e5-9e70-c82a142b6f9b<|endoftext|>
<commit_before>0842ca7e-2f67-11e5-80f4-6c40088e03e4<commit_msg>084988e4-2f67-11e5-912a-6c40088e03e4<commit_after>084988e4-2f67-11e5-912a-6c40088e03e4<|endoftext|>
<commit_before>773ee4d0-2d53-11e5-baeb-247703a38240<commit_msg>773f63e2-2d53-11e5-baeb-247703a38240<commit_after>773f63e2-2d53-11e5-baeb-247703a38240<|endoftext|>
<commit_before>757e047d-4b02-11e5-ad0d-28cfe9171a43<commit_msg>Did a thing<commit_after>758a8a8c-4b02-11e5-a1a9-28cfe9171a43<|endoftext|>
<commit_before>c6190a0f-2747-11e6-88e6-e0f84713e7b8<commit_msg>bug fix<commit_after>c63c98f3-2747-11e6-bd65-e0f84713e7b8<|endoftext|>
<commit_before>92323bc7-2d14-11e5-af21-0401358ea401<commit_msg>92323bc8-2d14-11e5-af21-0401358ea401<commit_after>92323bc8-2d14-11e5-af21-0401358ea401<|endoftext|>
<commit_before>07755900-ad59-11e7-8bf5-ac87a332f658<commit_msg>GOD DAMNED IT!<commit_after>08821b19-ad59-11e7-b111-ac87a332f658<|endoftext|>
<commit_before>dc805561-2747-11e6-bd11-e0f84713e7b8<commit_msg>updated some files<commit_after>dc8c799e-2747-11e6-b250-e0f84713e7b8<|endoftext|>
<commit_before>7c370fde-4b02-11e5-b323-28cfe9171a43<commit_msg>lets try again<commit_after>7c451bf8-4b02-11e5-887d-28cfe9171a43<|endoftext|>
<commit_before>0e84c4f8-2e4f-11e5-8813-28cfe91dbc4b<commit_msg>0e8c4105-2e4f-11e5-ae6c-28cfe91dbc4b<commit_after>0e8c4105-2e4f-11e5-ae6c-28cfe91dbc4b<|endoftext|>
<commit_before>85627984-2d15-11e5-af21-0401358ea401<commit_msg>85627985-2d15-11e5-af21-0401358ea401<commit_after>85627985-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>a8237264-35ca-11e5-a759-6c40088e03e4<commit_msg>a8309c00-35ca-11e5-9ae4-6c40088e03e4<commit_after>a8309c00-35ca-11e5-9ae4-6c40088e03e4<|endoftext|>
<commit_before>106bb330-2f67-11e5-a8cf-6c40088e03e4<commit_msg>1071f97a-2f67-11e5-a328-6c40088e03e4<commit_after>1071f97a-2f67-11e5-a328-6c40088e03e4<|endoftext|>
<commit_before>f3aae061-327f-11e5-9352-9cf387a8033e<commit_msg>f3b11126-327f-11e5-a8e4-9cf387a8033e<commit_after>f3b11126-327f-11e5-a8e4-9cf387a8033e<|endoftext|>
<commit_before>e0137052-585a-11e5-b95e-6c40088e03e4<commit_msg>e01b4138-585a-11e5-be73-6c40088e03e4<commit_after>e01b4138-585a-11e5-be73-6c40088e03e4<|endoftext|>
<commit_before>b4a6e1f3-4b02-11e5-a0a3-28cfe9171a43<commit_msg>Backup, rebase this later<commit_after>b4b2706b-4b02-11e5-84c2-28cfe9171a43<|endoftext|>
<commit_before>786ebaa6-2d53-11e5-baeb-247703a38240<commit_msg>786f41ce-2d53-11e5-baeb-247703a38240<commit_after>786f41ce-2d53-11e5-baeb-247703a38240<|endoftext|>
<commit_before>764ce733-2e4f-11e5-b4f3-28cfe91dbc4b<commit_msg>76536ceb-2e4f-11e5-b57e-28cfe91dbc4b<commit_after>76536ceb-2e4f-11e5-b57e-28cfe91dbc4b<|endoftext|>
<commit_before>d681d308-35ca-11e5-be40-6c40088e03e4<commit_msg>d6889914-35ca-11e5-9686-6c40088e03e4<commit_after>d6889914-35ca-11e5-9686-6c40088e03e4<|endoftext|>
<commit_before>ac108bd2-35ca-11e5-8923-6c40088e03e4<commit_msg>ac1753ca-35ca-11e5-a8c7-6c40088e03e4<commit_after>ac1753ca-35ca-11e5-a8c7-6c40088e03e4<|endoftext|>
<commit_before>e4773f8c-585a-11e5-80d4-6c40088e03e4<commit_msg>e47e3318-585a-11e5-af12-6c40088e03e4<commit_after>e47e3318-585a-11e5-af12-6c40088e03e4<|endoftext|>
<commit_before>5e589409-2d16-11e5-af21-0401358ea401<commit_msg>5e58940a-2d16-11e5-af21-0401358ea401<commit_after>5e58940a-2d16-11e5-af21-0401358ea401<|endoftext|>
<commit_before>1c16cac5-2e4f-11e5-a701-28cfe91dbc4b<commit_msg>1c207bd4-2e4f-11e5-96b3-28cfe91dbc4b<commit_after>1c207bd4-2e4f-11e5-96b3-28cfe91dbc4b<|endoftext|>
<commit_before>8431fc4a-2d15-11e5-af21-0401358ea401<commit_msg>8431fc4b-2d15-11e5-af21-0401358ea401<commit_after>8431fc4b-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>/* vim: set tabstop=4 autoindent: */ #include <iostream> using namespace std; int main(int argc,char * argv){ uint32_t i1 = 0; //Number of works float i2 = 0.0f; //Concurrency of works range from 0.0 to 1.0 cout<<"Enter I1(number of works): "; cin>>i1; cout<<endl; cout<<"Enter 2(Concurreny constant)(0-1): "; cin>>i2; cout<<endl; return 0; } <commit_msg>I2 input message fixed<commit_after>/* vim: set tabstop=4 autoindent: */ #include <iostream> using namespace std; int main(int argc,char * argv){ uint32_t i1 = 0; //Number of works float i2 = 0.0f; //Concurrency of works range from 0.0 to 1.0 cout<<"Enter I1(number of works): "; cin>>i1; cout<<endl; cout<<"Enter I2(Concurreny constant)(0-1): "; cin>>i2; cout<<endl; return 0; } <|endoftext|>
<commit_before>07bf7aac-2f67-11e5-9136-6c40088e03e4<commit_msg>07c64210-2f67-11e5-9766-6c40088e03e4<commit_after>07c64210-2f67-11e5-9766-6c40088e03e4<|endoftext|>
<commit_before>209b7292-2f67-11e5-b031-6c40088e03e4<commit_msg>20a21a98-2f67-11e5-8aee-6c40088e03e4<commit_after>20a21a98-2f67-11e5-8aee-6c40088e03e4<|endoftext|>
<commit_before>740fb638-5216-11e5-957d-6c40088e03e4<commit_msg>7416680c-5216-11e5-a618-6c40088e03e4<commit_after>7416680c-5216-11e5-a618-6c40088e03e4<|endoftext|>
<commit_before>708e1c9a-2e3a-11e5-9f8f-c03896053bdd<commit_msg>709c9e30-2e3a-11e5-97f1-c03896053bdd<commit_after>709c9e30-2e3a-11e5-97f1-c03896053bdd<|endoftext|>
<commit_before>8562799e-2d15-11e5-af21-0401358ea401<commit_msg>8562799f-2d15-11e5-af21-0401358ea401<commit_after>8562799f-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>/********************************************************* Version 1.100 Code provided by Gustavo Carneiro, Anthony Dick for the course COMP SCI 3014/7090 Computer Graphics School of Computer Science University of Adelaide Permission is granted for anyone to copy, use, modify, or distribute this program and accompanying programs and documents for any purpose, provided this copyright notice is retained and prominently displayed, along with a note saying that the original programs are available from the aforementioned course web page. The programs and documents are distributed without any warranty, express or implied. As the programs were written for research purposes only, they have not been tested to the degree that would be advisable in any important application. All use of these programs is entirely at the user's own risk. *********************************************************/ /** * Draws a single cube in front of the camera. * Toggles Projection matrix, and depth buffer. */ #include <iostream> #include <stdlib.h> #include <iomanip> #include <stdio.h> #include <fstream> #include <GL/glew.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" #include "glm/gtc/type_ptr.hpp" #include "model_data.h" #include "model.h" #include "renderer.h" #include "camera.h" #include "controller.h" #define STB_IMAGE_IMPLEMENTATION #include "lib/stb_image/stb_image.h" Renderer *g_renderer; Controller *g_controller; // Our shader program GLuint g_program_id[3]; // Background controls enum Colours { kBlue = 0, kGrey, kBlack, kOldGold }; int g_background = kOldGold; glm::vec3 g_colour = glm::vec3(0.71,0.61,0.23); // Lighting Globals int g_lighting_mode = 1; // Fog global int g_fog_mode = 0; // Rendering Toggle Vars bool g_coord_axis = true; // Camera object Camera * g_camera; int g_window_x = 640; int g_window_y = 480; void UpdateProjection() { glm::mat4 projection = glm::perspective(g_camera->aspect(), float(g_window_x / g_window_y), 0.1f, 100.0f); for (unsigned int i = 0; i < 3; i++) { glUseProgram(g_program_id[i]); int projHandle = glGetUniformLocation(g_program_id[i], "projection_matrix"); assert(projHandle != -1 && "Uniform: projection_matrix was not an active uniform label - See EnableAxis in Renderer"); glUniformMatrix4fv( projHandle, 1, false, glm::value_ptr(projection) ); } } /** * Renders a frame of the state and shaders we have set up to the window */ void render() { glClearColor(g_colour.x, g_colour.y, g_colour.z, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); g_camera->UpdateCamera(); UpdateProjection(); // Render ALL //g_renderer->Render(); // This renders model 0 // g_controller->Render(0); // Renders the car model // g_controller->DrawCar(); g_controller->Draw(); // g_controller->RenderTerrain(); // Render axis last so on top if (g_coord_axis) { // g_controller->RenderAxis(); } glUseProgram(0); glBindVertexArray(0); glutSwapBuffers(); glFlush(); } // FPS Counter Vars long g_past = 0; int g_frames = 0; void idle() { long time = glutGet(GLUT_ELAPSED_TIME); // FPS counter, only print FPS in terminal when it is not 60 g_frames += 1; if (static_cast<float>(time - g_past) / 1000.0f >= 1.0f) { if (g_frames != 60) { std::cout << "FPS: " << g_frames << std::endl; } g_frames = 0; g_past = time; } // Keyboard camera movement tick g_camera->Movement(); // Headlight dynamic lighting if (g_lighting_mode == 0) { float x,y,z; x = g_camera->cam_pos().x; y = g_camera->cam_pos().y; z = g_camera->cam_pos().z; g_controller->SetLightPosition(x,y,z,1.0f); } glutPostRedisplay(); } void MouseFunc(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON) { g_camera->set_is_right_button(true); } else { g_camera->set_is_right_button(false); } if (button == GLUT_LEFT_BUTTON) { g_camera->set_is_left_button(true); } else { g_camera->set_is_left_button(false); } g_camera->UpdatePreviousMouse(x,y); } void MotionFunc(int x, int y) { if (g_camera->is_right_button()) { g_camera->ChangeZoom(y); } if (g_camera->is_left_button()) { g_camera->ChangeDirection(x,y); } glutPostRedisplay(); g_camera->UpdatePreviousMouse(x,y); } void SpecialPressed( int key, int x, int y ) { g_camera->KeyPressed(key); } void SpecialReleased( int key, int x, int y ) { g_camera->KeyReleased(key); } /** * Called while a keyboard key press is detected * This GLUT functions is not OpenGL specific, but allows interactivity to our programs * @param key, the keyboard key that made the event * @param x, not used * @param y, not used */ void keyboardDown(unsigned char key, int x, int y) { // We simply check the key argument against characters we care about, in this case A and D switch(key) { case 'f': { g_fog_mode = (g_fog_mode + 1) % 5; glUseProgram(g_program_id[2]); int fogModeHandle = glGetUniformLocation(g_program_id[2], "fog_mode"); glUniform1i(fogModeHandle, g_fog_mode); glutPostRedisplay(); break; } case 27: // escape key pressed exit(0); break; case 'd': // Toggle depth test if ( glIsEnabled( GL_DEPTH_TEST ) ) { glDisable( GL_DEPTH_TEST ); } else { glEnable( GL_DEPTH_TEST ); } glutPostRedisplay(); break; case 's': glutPostRedisplay(); break; case 'c': if (g_coord_axis) { g_coord_axis = false; } else { g_coord_axis = true; } glutPostRedisplay(); break; case 'b': g_background++; if (g_background > 3) g_background = 0; if (g_background == kBlue) { g_colour.x = 0; g_colour.y = 0; g_colour.z = 1; } else if (g_background == kGrey) { g_colour.x = 0.7; g_colour.y = 0.7; g_colour.z = 0.7; } else if (g_background == kBlack) { g_colour.x = 0; g_colour.y = 0; g_colour.z = 0; } else if (g_background == kOldGold) { g_colour.x = 0.71; g_colour.y = 0.61; g_colour.z = 0.23; } glutPostRedisplay(); break; case 'l': if (g_lighting_mode == 0) { std::cout << "Lighting Mode = Overhead (Directional) Static" << std::endl; g_lighting_mode = 1; float overhead_light = (g_controller->GetMax(0, Controller::kY) + 1) * 2; // Ambient light disabled as per specs g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(0.7,0.7,1), glm::vec3(1,1,1)); g_controller->SetLightPosition(0,overhead_light,0,0); } else if (g_lighting_mode == 1) { std::cout << "Lighting Mode = Headlight (Point) Static" << std::endl; g_lighting_mode = 2; float front_light = (g_controller->GetMax(0, Controller::kZ) + 1) * 2; // Ambient light disabled as per specs g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(1,1,1), glm::vec3(1,1,1)); g_controller->SetLightPosition(0,0,front_light,1.0f); } else if (g_lighting_mode == 2){ std::cout << "Lighting Mode = None (Texturing Only)" << std::endl; g_lighting_mode = 3; g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(0,0,0), glm::vec3(0,0,0), 0); } else { std::cout << "Lighting Mode = Headlight (Point) Dynamic (Follows Camera)" << std::endl; g_lighting_mode = 0; g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(1,1,1), glm::vec3(1,1,1)); // Dynamic headlight lighting in render // Triggered by g_light_mode == 0 } glutPostRedisplay(); break; } } /** * Program entry. Sets up OpenGL state, GLSL Shaders and GLUT window and function call backs * Takes no arguments */ int main(int argc, char **argv) { // assert(argc > 1 && "provide Arg1 of .obj file"); std::cout << "Movement: Arrow keys move forward/backward and strafe left/right\n"; std::cout << "Movement: Hold left mouse button to change direction\n"; std::cout << "Movement: Hold right mouse button to zoom\n"; std::cout << "Controls: 'b' key to change Background Colour\n"; std::cout << "Controls: 'd' key to toggle Depth Testing\n"; std::cout << "Controls: 'c' key to toggle Axis Coordinates\n"; std::cout << "Controls: 'l' key to Cycle Lighting\n\n"; // std::cout << "Controls: 's' key to toggle Wireframe\n\n"; std::cout << "Controls: 'Esc' key to Quit\n\n"; // Set up GLUT window glutInit(&argc, argv); glutInitWindowPosition(100, 0); glutInitWindowSize(g_window_x, g_window_y); #ifdef __APPLE__ glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE); #else glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); #endif glutCreateWindow("Many Attributes"); // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } // GL stateglUseProgram(g_program_id[i]); ; glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); g_program_id[0] = LoadShaders("shaders/wireframe.vert", "shaders/wireframe.frag"); if (g_program_id[0] == 0) return 1; g_program_id[1] = LoadShaders("shaders/coord.vert", "shaders/coord.frag"); if (g_program_id[1] == 0) return 1; g_program_id[2] = LoadShaders("shaders/shaded.vert", "shaders/shaded.frag"); if (g_program_id[2] == 0) return 1; g_renderer = new Renderer(); //Construct Axis VAO g_renderer->EnableAxis(g_program_id[1]); g_controller = new Controller(g_renderer); //Texture Shader // g_renderer->AddModel(g_program_id[2], std::string(argv[1])); g_controller->AddModel(g_program_id[2], "models/Spider-Man/Spider-Man.obj"); g_controller->AddModel(g_program_id[2], "models/Car/car-n.obj", true); //Setup default overhead light float overhead_light = (g_controller->GetMax(0, Controller::kY) + 1) * 2; // Last 0 => w = 0, meaning light doesn't have position => directional light g_controller->SetLightPosition(0,overhead_light,0,0); // Setup camera global g_camera = g_controller->camera(); // Setup terrain g_controller->EnableTerrain(g_program_id[2]); // Here we set a new function callback which is the GLUT handling of keyboard input glutKeyboardFunc(keyboardDown); glutMotionFunc(MotionFunc); glutMouseFunc(MouseFunc); glutSpecialFunc(SpecialPressed); glutSpecialUpFunc(SpecialReleased); glutIdleFunc(idle); glutDisplayFunc(render); glutMainLoop(); return 0; } <commit_msg>Fixes #8<commit_after>/********************************************************* Version 1.100 Code provided by Gustavo Carneiro, Anthony Dick for the course COMP SCI 3014/7090 Computer Graphics School of Computer Science University of Adelaide Permission is granted for anyone to copy, use, modify, or distribute this program and accompanying programs and documents for any purpose, provided this copyright notice is retained and prominently displayed, along with a note saying that the original programs are available from the aforementioned course web page. The programs and documents are distributed without any warranty, express or implied. As the programs were written for research purposes only, they have not been tested to the degree that would be advisable in any important application. All use of these programs is entirely at the user's own risk. *********************************************************/ /** * Draws a single cube in front of the camera. * Toggles Projection matrix, and depth buffer. */ #include <iostream> #include <stdlib.h> #include <iomanip> #include <stdio.h> #include <fstream> #include <GL/glew.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" #include "glm/gtc/type_ptr.hpp" #include "model_data.h" #include "model.h" #include "renderer.h" #include "camera.h" #include "controller.h" #define STB_IMAGE_IMPLEMENTATION #include "lib/stb_image/stb_image.h" Renderer *g_renderer; Controller *g_controller; // Our shader program GLuint g_program_id[3]; // Background controls enum Colours { kBlue = 0, kGrey, kBlack, kOldGold }; int g_background = kOldGold; glm::vec3 g_colour = glm::vec3(0.71,0.61,0.23); // Lighting Globals int g_lighting_mode = 1; // Fog global int g_fog_mode = 0; // Rendering Toggle Vars bool g_coord_axis = true; // Camera object Camera * g_camera; int g_window_x = 640; int g_window_y = 480; void UpdateProjection() { for (unsigned int i = 0; i < 3; i++) { glUseProgram(g_program_id[i]); glm::mat4 projection = glm::perspective(g_camera->aspect(), float(g_window_x / g_window_y), 0.1f, 100.0f); int projHandle = glGetUniformLocation(g_program_id[i], "projection_matrix"); assert(projHandle != -1 && "Uniform: projection_matrix was not an active uniform label - See EnableAxis in Renderer"); glUniformMatrix4fv( projHandle, 1, false, glm::value_ptr(projection) ); } } /** * Renders a frame of the state and shaders we have set up to the window */ void render() { glClearColor(g_colour.x, g_colour.y, g_colour.z, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); g_camera->UpdateCamera(); UpdateProjection(); // Render ALL //g_renderer->Render(); // This renders model 0 // g_controller->Render(0); // Renders the car model // g_controller->DrawCar(); g_controller->Draw(); // g_controller->RenderTerrain(); // Render axis last so on top if (g_coord_axis) { // g_controller->RenderAxis(); } glUseProgram(0); glBindVertexArray(0); glutSwapBuffers(); glFlush(); } // FPS Counter Vars long g_past = 0; int g_frames = 0; void idle() { long time = glutGet(GLUT_ELAPSED_TIME); // FPS counter, only print FPS in terminal when it is not 60 g_frames += 1; if (static_cast<float>(time - g_past) / 1000.0f >= 1.0f) { if (g_frames != 60) { std::cout << "FPS: " << g_frames << std::endl; } g_frames = 0; g_past = time; } // Keyboard camera movement tick g_camera->Movement(); // Headlight dynamic lighting if (g_lighting_mode == 0) { float x,y,z; x = g_camera->cam_pos().x; y = g_camera->cam_pos().y; z = g_camera->cam_pos().z; g_controller->SetLightPosition(x,y,z,1.0f); } glutPostRedisplay(); } void MouseFunc(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON) { g_camera->set_is_right_button(true); } else { g_camera->set_is_right_button(false); } if (button == GLUT_LEFT_BUTTON) { g_camera->set_is_left_button(true); } else { g_camera->set_is_left_button(false); } g_camera->UpdatePreviousMouse(x,y); } void MotionFunc(int x, int y) { if (g_camera->is_right_button()) { g_camera->ChangeZoom(y); } if (g_camera->is_left_button()) { g_camera->ChangeDirection(x,y); } glutPostRedisplay(); g_camera->UpdatePreviousMouse(x,y); } void SpecialPressed( int key, int x, int y ) { g_camera->KeyPressed(key); } void SpecialReleased( int key, int x, int y ) { g_camera->KeyReleased(key); } /** * Called while a keyboard key press is detected * This GLUT functions is not OpenGL specific, but allows interactivity to our programs * @param key, the keyboard key that made the event * @param x, not used * @param y, not used */ void keyboardDown(unsigned char key, int x, int y) { // We simply check the key argument against characters we care about, in this case A and D switch(key) { case 'f': { g_fog_mode = (g_fog_mode + 1) % 5; glUseProgram(g_program_id[2]); int fogModeHandle = glGetUniformLocation(g_program_id[2], "fog_mode"); glUniform1i(fogModeHandle, g_fog_mode); glutPostRedisplay(); break; } case 27: // escape key pressed exit(0); break; case 'd': // Toggle depth test if ( glIsEnabled( GL_DEPTH_TEST ) ) { glDisable( GL_DEPTH_TEST ); } else { glEnable( GL_DEPTH_TEST ); } glutPostRedisplay(); break; case 's': glutPostRedisplay(); break; case 'c': if (g_coord_axis) { g_coord_axis = false; } else { g_coord_axis = true; } glutPostRedisplay(); break; case 'b': g_background++; if (g_background > 3) g_background = 0; if (g_background == kBlue) { g_colour.x = 0; g_colour.y = 0; g_colour.z = 1; } else if (g_background == kGrey) { g_colour.x = 0.7; g_colour.y = 0.7; g_colour.z = 0.7; } else if (g_background == kBlack) { g_colour.x = 0; g_colour.y = 0; g_colour.z = 0; } else if (g_background == kOldGold) { g_colour.x = 0.71; g_colour.y = 0.61; g_colour.z = 0.23; } glutPostRedisplay(); break; case 'l': if (g_lighting_mode == 0) { std::cout << "Lighting Mode = Overhead (Directional) Static" << std::endl; g_lighting_mode = 1; float overhead_light = (g_controller->GetMax(0, Controller::kY) + 1) * 2; // Ambient light disabled as per specs g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(0.7,0.7,1), glm::vec3(1,1,1)); g_controller->SetLightPosition(0,overhead_light,0,0); } else if (g_lighting_mode == 1) { std::cout << "Lighting Mode = Headlight (Point) Static" << std::endl; g_lighting_mode = 2; float front_light = (g_controller->GetMax(0, Controller::kZ) + 1) * 2; // Ambient light disabled as per specs g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(1,1,1), glm::vec3(1,1,1)); g_controller->SetLightPosition(0,0,front_light,1.0f); } else if (g_lighting_mode == 2){ std::cout << "Lighting Mode = None (Texturing Only)" << std::endl; g_lighting_mode = 3; g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(0,0,0), glm::vec3(0,0,0), 0); } else { std::cout << "Lighting Mode = Headlight (Point) Dynamic (Follows Camera)" << std::endl; g_lighting_mode = 0; g_controller->SetupLighting(g_program_id[2], glm::vec3(0,0,0), glm::vec3(1,1,1), glm::vec3(1,1,1)); // Dynamic headlight lighting in render // Triggered by g_light_mode == 0 } glutPostRedisplay(); break; } } /** * Program entry. Sets up OpenGL state, GLSL Shaders and GLUT window and function call backs * Takes no arguments */ int main(int argc, char **argv) { // assert(argc > 1 && "provide Arg1 of .obj file"); std::cout << "Movement: Arrow keys move forward/backward and strafe left/right\n"; std::cout << "Movement: Hold left mouse button to change direction\n"; std::cout << "Movement: Hold right mouse button to zoom\n"; std::cout << "Controls: 'b' key to change Background Colour\n"; std::cout << "Controls: 'd' key to toggle Depth Testing\n"; std::cout << "Controls: 'c' key to toggle Axis Coordinates\n"; std::cout << "Controls: 'l' key to Cycle Lighting\n\n"; // std::cout << "Controls: 's' key to toggle Wireframe\n\n"; std::cout << "Controls: 'Esc' key to Quit\n\n"; // Set up GLUT window glutInit(&argc, argv); glutInitWindowPosition(100, 0); glutInitWindowSize(g_window_x, g_window_y); #ifdef __APPLE__ glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE); #else glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); #endif glutCreateWindow("Many Attributes"); // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } // GL stateglUseProgram(g_program_id[i]); ; glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); g_program_id[0] = LoadShaders("shaders/wireframe.vert", "shaders/wireframe.frag"); if (g_program_id[0] == 0) return 1; g_program_id[1] = LoadShaders("shaders/coord.vert", "shaders/coord.frag"); if (g_program_id[1] == 0) return 1; g_program_id[2] = LoadShaders("shaders/shaded.vert", "shaders/shaded.frag"); if (g_program_id[2] == 0) return 1; g_renderer = new Renderer(); //Construct Axis VAO g_renderer->EnableAxis(g_program_id[1]); g_controller = new Controller(g_renderer); //Texture Shader // g_renderer->AddModel(g_program_id[2], std::string(argv[1])); g_controller->AddModel(g_program_id[2], "models/Spider-Man/Spider-Man.obj"); g_controller->AddModel(g_program_id[2], "models/Car/car-n.obj", true); //Setup default overhead light float overhead_light = (g_controller->GetMax(0, Controller::kY) + 1) * 2; // Last 0 => w = 0, meaning light doesn't have position => directional light g_controller->SetLightPosition(0,overhead_light,0,0); // Setup camera global g_camera = g_controller->camera(); // Setup terrain g_controller->EnableTerrain(g_program_id[2]); // Here we set a new function callback which is the GLUT handling of keyboard input glutKeyboardFunc(keyboardDown); glutMotionFunc(MotionFunc); glutMouseFunc(MouseFunc); glutSpecialFunc(SpecialPressed); glutSpecialUpFunc(SpecialReleased); glutIdleFunc(idle); glutDisplayFunc(render); glutMainLoop(); return 0; } <|endoftext|>
<commit_before>a2d94a18-35ca-11e5-9c9b-6c40088e03e4<commit_msg>a2e0fa68-35ca-11e5-9220-6c40088e03e4<commit_after>a2e0fa68-35ca-11e5-9220-6c40088e03e4<|endoftext|>
<commit_before>9dbace58-35ca-11e5-b80a-6c40088e03e4<commit_msg>9dc16010-35ca-11e5-b818-6c40088e03e4<commit_after>9dc16010-35ca-11e5-b818-6c40088e03e4<|endoftext|>
<commit_before>7137a994-2e4f-11e5-9569-28cfe91dbc4b<commit_msg>713f5338-2e4f-11e5-acde-28cfe91dbc4b<commit_after>713f5338-2e4f-11e5-acde-28cfe91dbc4b<|endoftext|>
<commit_before>a3880b98-35ca-11e5-9f44-6c40088e03e4<commit_msg>a38f5ef0-35ca-11e5-bbf7-6c40088e03e4<commit_after>a38f5ef0-35ca-11e5-bbf7-6c40088e03e4<|endoftext|>
<commit_before>22158359-ad59-11e7-8a21-ac87a332f658<commit_msg>Added that feature we discussed on... Was it monday?<commit_after>227226bd-ad59-11e7-aa0c-ac87a332f658<|endoftext|>
<commit_before>694f6b36-2fa5-11e5-8eda-00012e3d3f12<commit_msg>69513ff4-2fa5-11e5-966b-00012e3d3f12<commit_after>69513ff4-2fa5-11e5-966b-00012e3d3f12<|endoftext|>
<commit_before>61665721-2e4f-11e5-b01a-28cfe91dbc4b<commit_msg>616d1ee1-2e4f-11e5-95b7-28cfe91dbc4b<commit_after>616d1ee1-2e4f-11e5-95b7-28cfe91dbc4b<|endoftext|>
<commit_before>5e589451-2d16-11e5-af21-0401358ea401<commit_msg>5e589452-2d16-11e5-af21-0401358ea401<commit_after>5e589452-2d16-11e5-af21-0401358ea401<|endoftext|>
<commit_before>8faadbe1-ad59-11e7-bf80-ac87a332f658<commit_msg>Nope, didn't work, now it does<commit_after>90d765d7-ad59-11e7-9bcf-ac87a332f658<|endoftext|>
<commit_before>70633f54-2fa5-11e5-8058-00012e3d3f12<commit_msg>70651414-2fa5-11e5-80bc-00012e3d3f12<commit_after>70651414-2fa5-11e5-80bc-00012e3d3f12<|endoftext|>
<commit_before>d36a681a-585a-11e5-9a4f-6c40088e03e4<commit_msg>d371407a-585a-11e5-bd9f-6c40088e03e4<commit_after>d371407a-585a-11e5-bd9f-6c40088e03e4<|endoftext|>
<commit_before>#include "html5viewer/html5viewer.h" #include "ClientWrapper.hpp" #include "Utilities.hpp" #include "MainWindow.hpp" #include <boost/thread.hpp> #include <bts/blockchain/config.hpp> #include <bts/wallet/url.hpp> #include <signal.h> #include <QApplication> #include <QSettings> #include <QPixmap> #include <QErrorMessage> #include <QSplashScreen> #include <QDir> #include <QWebSettings> #include <QWebPage> #include <QWebFrame> #include <QJsonDocument> #include <QGraphicsWebView> #include <QTimer> #include <QAuthenticator> #include <QNetworkReply> #include <QResource> #include <QGraphicsWidget> #include <QMainWindow> #include <QMenuBar> #include <QLayout> #include <QLocalSocket> #include <QLocalServer> #include <QMessageBox> #include <boost/program_options.hpp> #include <bts/client/client.hpp> #include <bts/net/upnp.hpp> #include <bts/blockchain/chain_database.hpp> #include <bts/rpc/rpc_server.hpp> #include <bts/cli/cli.hpp> #include <bts/utilities/git_revision.hpp> #include <fc/filesystem.hpp> #include <fc/thread/thread.hpp> #include <fc/log/file_appender.hpp> #include <fc/log/logger_config.hpp> #include <fc/io/json.hpp> #include <fc/reflect/variant.hpp> #include <fc/git_revision.hpp> #include <fc/io/json.hpp> #include <fc/log/logger_config.hpp> #include <fc/signals.hpp> #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> #include <iomanip> void setupMenus(ClientWrapper* client, MainWindow* mainWindow) { auto accountMenu = mainWindow->accountMenu(); accountMenu->addAction("&Go to My Accounts", mainWindow, SLOT(goToMyAccounts())); accountMenu->addAction("&Create Account", mainWindow, SLOT(goToCreateAccount())); accountMenu->addAction("&Import Account")->setEnabled(false); } void prepareStartupSequence(ClientWrapper* client, Html5Viewer* viewer, MainWindow* mainWindow, QSplashScreen* splash) { viewer->webView()->page()->mainFrame()->addToJavaScriptWindowObject("bitshares", client); viewer->webView()->page()->mainFrame()->addToJavaScriptWindowObject("magic_unicorn", new Utilities, QWebFrame::ScriptOwnership); QObject::connect(viewer->webView()->page()->networkAccessManager(), &QNetworkAccessManager::authenticationRequired, [client](QNetworkReply*, QAuthenticator *auth) { auth->setUser(client->http_url().userName()); auth->setPassword(client->http_url().password()); }); client->connect(client, &ClientWrapper::initialized, [viewer,client,mainWindow]() { ilog( "Client initialized; loading web interface from ${url}", ("url", client->http_url().toString().toStdString()) ); client->status_update("Calculating last 3 digits of pi"); viewer->webView()->load(client->http_url()); //Now we know the URL of the app, so we can create the items in the Accounts menu setupMenus(client, mainWindow); }); auto loadFinishedConnection = std::make_shared<QMetaObject::Connection>(); *loadFinishedConnection = viewer->connect(viewer->webView(), &QGraphicsWebView::loadFinished, [mainWindow,splash,viewer,loadFinishedConnection](bool ok) { ilog( "Webview loaded: ${status}", ("status", ok) ); viewer->disconnect(*loadFinishedConnection); mainWindow->show(); splash->finish(mainWindow); mainWindow->processDeferredUrl(); }); client->connect(client, &ClientWrapper::error, [=](QString errorString) { splash->hide(); QMessageBox::critical(nullptr, QObject::tr("Error"), errorString); exit(1); }); client->connect(client, &ClientWrapper::status_update, [=](QString messageString) { splash->showMessage(messageString, Qt::AlignCenter | Qt::AlignBottom, Qt::white); }); } QLocalServer* startSingleInstanceServer(MainWindow* mainWindow) { QLocalServer* singleInstanceServer = new QLocalServer(); if( !singleInstanceServer->listen(BTS_BLOCKCHAIN_NAME) ) { std::cerr << "Could not start new instance listener. Attempting to remove defunct listener... "; QLocalServer::removeServer(BTS_BLOCKCHAIN_NAME); if( !singleInstanceServer->listen(BTS_BLOCKCHAIN_NAME) ) { std::cerr << "Failed to start new instance listener: " << singleInstanceServer->errorString().toStdString() << std::endl; exit(1); } std::cerr << "Success.\n"; } std::cout << "Listening for new instances on " << singleInstanceServer->fullServerName().toStdString() << std::endl; singleInstanceServer->connect(singleInstanceServer, &QLocalServer::newConnection, [singleInstanceServer,mainWindow](){ QLocalSocket* zygote = singleInstanceServer->nextPendingConnection(); QEventLoop waitLoop; zygote->connect(zygote, &QLocalSocket::readyRead, &waitLoop, &QEventLoop::quit); QTimer::singleShot(1000, &waitLoop, SLOT(quit())); waitLoop.exec(); mainWindow->raise(); mainWindow->activateWindow(); if( zygote->bytesAvailable() ) { QByteArray message = zygote->readLine(); ilog("Got message from new instance: ${msg}", ("msg",message.data())); mainWindow->processCustomUrl(message); } zygote->close(); delete zygote; }); return singleInstanceServer; } int main( int argc, char** argv ) { QCoreApplication::setOrganizationName( "BitShares" ); QCoreApplication::setOrganizationDomain( "bitshares.org" ); QCoreApplication::setApplicationName( BTS_BLOCKCHAIN_NAME ); QApplication app(argc, argv); app.setWindowIcon(QIcon(":/images/qtapp.ico")); MainWindow mainWindow; //Custom URL handling. OSX handles this differently from Windows and Linux //On OSX, the OS will always pass the URL as an event to QApplication. //Windows and Linux will just run our program with the URL as an argument. #ifdef __APPLE__ //Install OSX event handler app.installEventFilter(&mainWindow); #endif //We'll go ahead and leave Win/Lin URL handling available in OSX too QLocalSocket* sock = new QLocalSocket(); sock->connectToServer(BTS_BLOCKCHAIN_NAME); if( sock->waitForConnected(100) ) { if( argc > 1 && app.arguments()[1].startsWith(QString(CUSTOM_URL_SCHEME) + ":") ) { //Need to open a custom URL. Pass it to pre-existing instance. std::cout << "Found instance already running. Sending message and exiting." << std::endl; sock->write(argv[1]); sock->waitForBytesWritten(); sock->close(); } //Note that we connected, but may not have sent anything. This means that another instance is already //running. The fact that we connected prompted it to request focus; we will just exit now. delete sock; return 0; } else { if( argc > 1 && app.arguments()[1].startsWith(QString(CUSTOM_URL_SCHEME) + ":") ) { //No other instance running. Handle URL when we get started up. mainWindow.deferCustomUrl(app.arguments()[1]); } //Could not connect to already-running instance. Start a server so future instances connect to us QLocalServer* singleInstanceServer = startSingleInstanceServer(&mainWindow); app.connect(&app, &QApplication::aboutToQuit, singleInstanceServer, &QLocalServer::deleteLater); } delete sock; auto viewer = new Html5Viewer; ClientWrapper* client = new ClientWrapper; //#ifdef NDEBUG app.connect(&app, &QApplication::aboutToQuit, [client](){ client->close(); exit(0); }); //#endif mainWindow.setCentralWidget(viewer); mainWindow.setClientWrapper(client); QTimer fc_tasks; fc_tasks.connect( &fc_tasks, &QTimer::timeout, [](){ fc::usleep( fc::microseconds( 1000 ) ); } ); fc_tasks.start(33); QPixmap pixmap(":/images/splash_screen.jpg"); QSplashScreen splash(pixmap); splash.showMessage(QObject::tr("Loading configuration..."), Qt::AlignCenter | Qt::AlignBottom, Qt::white); splash.show(); prepareStartupSequence(client, viewer, &mainWindow, &splash); QWebSettings::globalSettings()->setAttribute( QWebSettings::PluginsEnabled, false ); try { client->initialize(); return app.exec(); } catch ( const fc::exception& e) { elog( "${e}", ("e",e.to_detail_string() ) ); QErrorMessage::qtHandler()->showMessage( e.to_string().c_str() ); } } <commit_msg>Remove clean exit hack<commit_after>#include "html5viewer/html5viewer.h" #include "ClientWrapper.hpp" #include "Utilities.hpp" #include "MainWindow.hpp" #include <boost/thread.hpp> #include <bts/blockchain/config.hpp> #include <bts/wallet/url.hpp> #include <signal.h> #include <QApplication> #include <QSettings> #include <QPixmap> #include <QErrorMessage> #include <QSplashScreen> #include <QDir> #include <QWebSettings> #include <QWebPage> #include <QWebFrame> #include <QJsonDocument> #include <QGraphicsWebView> #include <QTimer> #include <QAuthenticator> #include <QNetworkReply> #include <QResource> #include <QGraphicsWidget> #include <QMainWindow> #include <QMenuBar> #include <QLayout> #include <QLocalSocket> #include <QLocalServer> #include <QMessageBox> #include <boost/program_options.hpp> #include <bts/client/client.hpp> #include <bts/net/upnp.hpp> #include <bts/blockchain/chain_database.hpp> #include <bts/rpc/rpc_server.hpp> #include <bts/cli/cli.hpp> #include <bts/utilities/git_revision.hpp> #include <fc/filesystem.hpp> #include <fc/thread/thread.hpp> #include <fc/log/file_appender.hpp> #include <fc/log/logger_config.hpp> #include <fc/io/json.hpp> #include <fc/reflect/variant.hpp> #include <fc/git_revision.hpp> #include <fc/io/json.hpp> #include <fc/log/logger_config.hpp> #include <fc/signals.hpp> #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> #include <iomanip> void setupMenus(ClientWrapper* client, MainWindow* mainWindow) { auto accountMenu = mainWindow->accountMenu(); accountMenu->addAction("&Go to My Accounts", mainWindow, SLOT(goToMyAccounts())); accountMenu->addAction("&Create Account", mainWindow, SLOT(goToCreateAccount())); accountMenu->addAction("&Import Account")->setEnabled(false); } void prepareStartupSequence(ClientWrapper* client, Html5Viewer* viewer, MainWindow* mainWindow, QSplashScreen* splash) { viewer->webView()->page()->mainFrame()->addToJavaScriptWindowObject("bitshares", client); viewer->webView()->page()->mainFrame()->addToJavaScriptWindowObject("magic_unicorn", new Utilities, QWebFrame::ScriptOwnership); QObject::connect(viewer->webView()->page()->networkAccessManager(), &QNetworkAccessManager::authenticationRequired, [client](QNetworkReply*, QAuthenticator *auth) { auth->setUser(client->http_url().userName()); auth->setPassword(client->http_url().password()); }); client->connect(client, &ClientWrapper::initialized, [viewer,client,mainWindow]() { ilog( "Client initialized; loading web interface from ${url}", ("url", client->http_url().toString().toStdString()) ); client->status_update("Calculating last 3 digits of pi"); viewer->webView()->load(client->http_url()); //Now we know the URL of the app, so we can create the items in the Accounts menu setupMenus(client, mainWindow); }); auto loadFinishedConnection = std::make_shared<QMetaObject::Connection>(); *loadFinishedConnection = viewer->connect(viewer->webView(), &QGraphicsWebView::loadFinished, [mainWindow,splash,viewer,loadFinishedConnection](bool ok) { ilog( "Webview loaded: ${status}", ("status", ok) ); viewer->disconnect(*loadFinishedConnection); mainWindow->show(); splash->finish(mainWindow); mainWindow->processDeferredUrl(); }); client->connect(client, &ClientWrapper::error, [=](QString errorString) { splash->hide(); QMessageBox::critical(nullptr, QObject::tr("Error"), errorString); exit(1); }); client->connect(client, &ClientWrapper::status_update, [=](QString messageString) { splash->showMessage(messageString, Qt::AlignCenter | Qt::AlignBottom, Qt::white); }); } QLocalServer* startSingleInstanceServer(MainWindow* mainWindow) { QLocalServer* singleInstanceServer = new QLocalServer(); if( !singleInstanceServer->listen(BTS_BLOCKCHAIN_NAME) ) { std::cerr << "Could not start new instance listener. Attempting to remove defunct listener... "; QLocalServer::removeServer(BTS_BLOCKCHAIN_NAME); if( !singleInstanceServer->listen(BTS_BLOCKCHAIN_NAME) ) { std::cerr << "Failed to start new instance listener: " << singleInstanceServer->errorString().toStdString() << std::endl; exit(1); } std::cerr << "Success.\n"; } std::cout << "Listening for new instances on " << singleInstanceServer->fullServerName().toStdString() << std::endl; singleInstanceServer->connect(singleInstanceServer, &QLocalServer::newConnection, [singleInstanceServer,mainWindow](){ QLocalSocket* zygote = singleInstanceServer->nextPendingConnection(); QEventLoop waitLoop; zygote->connect(zygote, &QLocalSocket::readyRead, &waitLoop, &QEventLoop::quit); QTimer::singleShot(1000, &waitLoop, SLOT(quit())); waitLoop.exec(); mainWindow->raise(); mainWindow->activateWindow(); if( zygote->bytesAvailable() ) { QByteArray message = zygote->readLine(); ilog("Got message from new instance: ${msg}", ("msg",message.data())); mainWindow->processCustomUrl(message); } zygote->close(); delete zygote; }); return singleInstanceServer; } int main( int argc, char** argv ) { QCoreApplication::setOrganizationName( "BitShares" ); QCoreApplication::setOrganizationDomain( "bitshares.org" ); QCoreApplication::setApplicationName( BTS_BLOCKCHAIN_NAME ); QApplication app(argc, argv); app.setWindowIcon(QIcon(":/images/qtapp.ico")); MainWindow mainWindow; //Custom URL handling. OSX handles this differently from Windows and Linux //On OSX, the OS will always pass the URL as an event to QApplication. //Windows and Linux will just run our program with the URL as an argument. #ifdef __APPLE__ //Install OSX event handler app.installEventFilter(&mainWindow); #endif //We'll go ahead and leave Win/Lin URL handling available in OSX too QLocalSocket* sock = new QLocalSocket(); sock->connectToServer(BTS_BLOCKCHAIN_NAME); if( sock->waitForConnected(100) ) { if( argc > 1 && app.arguments()[1].startsWith(QString(CUSTOM_URL_SCHEME) + ":") ) { //Need to open a custom URL. Pass it to pre-existing instance. std::cout << "Found instance already running. Sending message and exiting." << std::endl; sock->write(argv[1]); sock->waitForBytesWritten(); sock->close(); } //Note that we connected, but may not have sent anything. This means that another instance is already //running. The fact that we connected prompted it to request focus; we will just exit now. delete sock; return 0; } else { if( argc > 1 && app.arguments()[1].startsWith(QString(CUSTOM_URL_SCHEME) + ":") ) { //No other instance running. Handle URL when we get started up. mainWindow.deferCustomUrl(app.arguments()[1]); } //Could not connect to already-running instance. Start a server so future instances connect to us QLocalServer* singleInstanceServer = startSingleInstanceServer(&mainWindow); app.connect(&app, &QApplication::aboutToQuit, singleInstanceServer, &QLocalServer::deleteLater); } delete sock; auto viewer = new Html5Viewer; ClientWrapper* client = new ClientWrapper; app.connect(&app, &QApplication::aboutToQuit, client, &ClientWrapper::close); mainWindow.setCentralWidget(viewer); mainWindow.setClientWrapper(client); QTimer fc_tasks; fc_tasks.connect( &fc_tasks, &QTimer::timeout, [](){ fc::usleep( fc::microseconds( 1000 ) ); } ); fc_tasks.start(33); QPixmap pixmap(":/images/splash_screen.jpg"); QSplashScreen splash(pixmap); splash.showMessage(QObject::tr("Loading configuration..."), Qt::AlignCenter | Qt::AlignBottom, Qt::white); splash.show(); prepareStartupSequence(client, viewer, &mainWindow, &splash); QWebSettings::globalSettings()->setAttribute( QWebSettings::PluginsEnabled, false ); try { client->initialize(); return app.exec(); } catch ( const fc::exception& e) { elog( "${e}", ("e",e.to_detail_string() ) ); QErrorMessage::qtHandler()->showMessage( e.to_string().c_str() ); } } <|endoftext|>
<commit_before>7b3a346e-5216-11e5-baf5-6c40088e03e4<commit_msg>7b40c34a-5216-11e5-bbfd-6c40088e03e4<commit_after>7b40c34a-5216-11e5-bbfd-6c40088e03e4<|endoftext|>
<commit_before>85627907-2d15-11e5-af21-0401358ea401<commit_msg>85627908-2d15-11e5-af21-0401358ea401<commit_after>85627908-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>7b761946-5216-11e5-9f86-6c40088e03e4<commit_msg>7b7cb470-5216-11e5-ad61-6c40088e03e4<commit_after>7b7cb470-5216-11e5-ad61-6c40088e03e4<|endoftext|>
<commit_before>2471ae63-2d3e-11e5-b104-c82a142b6f9b<commit_msg>24d50e33-2d3e-11e5-87c1-c82a142b6f9b<commit_after>24d50e33-2d3e-11e5-87c1-c82a142b6f9b<|endoftext|>
<commit_before>#include "eHimage.h" #include "eHmatrix.h" #include "eHutils.h" #include "eHfacemodel.h" #include "eHfeatpyramid.h" #include "eHbox.h" #include "rapidxml-1.13/rapidxml.hpp" #include <iostream> #include <fstream> #include <vector> #include <string.h> #include <math.h> using std::ios; using std::cout; using std::endl; using std::vector; mat3d_ptr eHconv(const mat3d_ptr feats, const vector<facefilter_t> filters, int start, int end); mat3d_ptr eHhog(const image_ptr img, int sbin); void eHshiftdt(double* M, int* Ix, int* Iy, int lenx, int leny, int offx, int offy, int dstep, double* vals, int sizx, int sizy, double ax, double bx, double ay, double by); static inline int round2int(double x) { return ((x-floor(x))>0.5 ? (int)ceil(x) : (int)floor(x));} int main(int argc, char** argv){ //image_t* img = image_readJPG(argv[1]); image_t* img = image_readJPG("image/10081706_5.jpg"); //image_display(img,"test"); facemodel_t* model = facemodel_readFromFile("face_p146.xml"); //model->interval = 5; //facepyra_t* pyra = facepyra_create(img,model->interval,model->sbin,model->maxsize); //mat3d_ptr resp = eHconv(pyra->feat[10],model->filters,0,145); //mat3d_delete(resp); //facepyra_delete(pyra); vector<bbox_t> faces = facemodel_detect(img, model); facemodel_delete(model); image_delete(img); return 0; } <commit_msg>take command line arg<commit_after>#include "eHimage.h" #include "eHmatrix.h" #include "eHutils.h" #include "eHfacemodel.h" #include "eHfeatpyramid.h" #include "eHbox.h" #include "rapidxml-1.13/rapidxml.hpp" #include <iostream> #include <fstream> #include <vector> #include <string.h> #include <math.h> using std::ios; using std::cout; using std::endl; using std::vector; mat3d_ptr eHconv(const mat3d_ptr feats, const vector<facefilter_t> filters, int start, int end); mat3d_ptr eHhog(const image_ptr img, int sbin); void eHshiftdt(double* M, int* Ix, int* Iy, int lenx, int leny, int offx, int offy, int dstep, double* vals, int sizx, int sizy, double ax, double bx, double ay, double by); static inline int round2int(double x) { return ((x-floor(x))>0.5 ? (int)ceil(x) : (int)floor(x));} int main(int argc, char** argv){ image_t* img = NULL; if(argc<2) img = image_readJPG("image/10081706_5.jpg"); else img = image_readJPG(argv[1]); //image_display(img,"test"); facemodel_t* model = facemodel_readFromFile("face_p146.xml"); vector<bbox_t> faces = facemodel_detect(img, model); facemodel_delete(model); image_delete(img); return 0; } <|endoftext|>
<commit_before>0571501e-2f67-11e5-ba03-6c40088e03e4<commit_msg>057825f6-2f67-11e5-b70a-6c40088e03e4<commit_after>057825f6-2f67-11e5-b70a-6c40088e03e4<|endoftext|>
<commit_before>2c9b3117-2e4f-11e5-8ad7-28cfe91dbc4b<commit_msg>2ca341b0-2e4f-11e5-8db5-28cfe91dbc4b<commit_after>2ca341b0-2e4f-11e5-8db5-28cfe91dbc4b<|endoftext|>
<commit_before>#include <iostream> #include <string> #include <fstream> #include "main.h" #include "bond_angle.cpp" // #include "bond_length.cpp" using namespace std; /** * @mainpage The Gaussian Optimization Analytical Tool (GOAT) * * Welcome to the Gaussian Optimization Analytical Tool (GOAT) documentation site! * Users may find relevant info related to this program, a program designed to provide * structural analyses of biomolecules successfully optimized using Gaussian software. * * @short Main program * @file main.cpp * @author Kate Charbonnet, Hannah Lozano, and Thomas Summers * @param none * @return 0 on success * * The purpose of this program is to provide preliminary structural information on biomolecules * optimized using Gaussian computational chemistry software. Structural and chemical properties * identified include: element identification, bond length, bond order, central angles, and torsional * angles. Input of the file to be analyzed will result in an output file listing all the structural * information of the biomolecule. */ int main(int argc, char* argv[]) { ifstream inputfile; ofstream logfile; ifstream bond_angle; unsigned int count_line = 0; string line; string header1 = "Optimized Parameters"; string header2 = "Standard orientation:"; string print(string); //Check that input file was directed into the command line if (argc < 2) { cout << "Error: Inputfile not specified in command line\n"; return 1; } //Open the input file and check that it opened inputfile.open(argv[1]); if (!inputfile.is_open()) { cout << "Error: Unable to open the input file."; return 2; } //Generate a log file and check that it opened logfile.open("log.txt"); if (!logfile.is_open()) { cout << "Error: Unable to open the logfile."; return 3; } else { logfile << "Logfile for Gaussian Optimization Analytical Tool\n"; } //Search the input file for the first keywords while (getline(inputfile, line)) { count_line++; if (line.find(header1, 0) != string::npos) { cout << "Found: " << header1 << " at position " << count_line << endl; logfile << "Found: " << header1 << " at position " << count_line << endl; for (int i = 1912; i; --i) { logfile << line << "\n"; getline (inputfile, line); } } } inputfile.close(); cout << "Search Complete\n"; logfile << "Search Complete" << endl; logfile.close(); //Open the file bond_angle.cpp and check that it opened bond_angle.open("bond_angle.cpp"); if (!bond_angle.is_open()) { cout << "Error: Unable to open bond_angle file."; return 1; } //Close the file bond_angle.cpp bond_angle.close(); cout << "Bond angle calculation complete."; return 0; } <commit_msg>Main now able to extract desired chunk without integeric qualifier<commit_after>#include <iostream> #include <string> #include <fstream> #include "main.h" #include "bond_angle.cpp" // #include "bond_length.cpp" using namespace std; /** * @mainpage The Gaussian Optimization Analytical Tool (GOAT) * * Welcome to the Gaussian Optimization Analytical Tool (GOAT) documentation site! * Users may find relevant info related to this program, a program designed to provide * structural analyses of biomolecules successfully optimized using Gaussian software. * * @short Main program * @file main.cpp * @author Kate Charbonnet, Hannah Lozano, and Thomas Summers * @param none * @return 0 on success * * The purpose of this program is to provide preliminary structural information on biomolecules * optimized using Gaussian computational chemistry software. Structural and chemical properties * identified include: element identification, bond length, bond order, central angles, and torsional * angles. Input of the file to be analyzed will result in an output file listing all the structural * information of the biomolecule. */ int main(int argc, char* argv[]) { ifstream inputfile; ofstream logfile; ifstream bond_angle; string line; unsigned int count_line = 0; unsigned int total_lines = 0; string header1 = "Redundant internal coordinates found in file"; string footer1 = "Recover connectivity data from disk."; string print(string); //Check that input file was directed into the command line if (argc < 2) { cout << "Error: Inputfile not specified in command line\n"; return 1; } //Open the input file and check that it opened inputfile.open(argv[1]); if (!inputfile.is_open()) { cout << "Error: Unable to open the input file."; return 2; } //Generate a log file and check that it opened logfile.open("log.txt"); if (!logfile.is_open()) { cout << "Error: Unable to open the logfile."; return 3; } else { logfile << "Logfile for Gaussian Optimization Analytical Tool\n"; } //Search the input file for the first keywords while (getline(inputfile, line)) { count_line++; if (line.find(header1, 0) != string::npos) { cout << "Found: " << header1 << " at position " << count_line << endl; logfile << "Found: " << header1 << " at position " << count_line << endl; for (int i = 1; i > 0; ++i) { logfile << line << "\n"; getline (inputfile, line); if (line.find(footer1, 0) != string::npos) { cout << "Found: " << footer1 << endl; logfile << "Found: " << footer1 << endl; break; } } } } inputfile.close(); cout << "Search Complete\n"; logfile << "Search Complete" << endl; logfile.close(); //Open the file bond_angle.cpp and check that it opened bond_angle.open("bond_angle.cpp"); if (!bond_angle.is_open()) { cout << "Error: Unable to open bond_angle file."; return 1; } //Close the file bond_angle.cpp bond_angle.close(); cout << "Bond angle calculation complete."; return 0; } <|endoftext|>
<commit_before>d866f4a6-313a-11e5-941a-3c15c2e10482<commit_msg>d86d068f-313a-11e5-a1bd-3c15c2e10482<commit_after>d86d068f-313a-11e5-a1bd-3c15c2e10482<|endoftext|>
<commit_before>c3451363-327f-11e5-b9b9-9cf387a8033e<commit_msg>c34b5e7d-327f-11e5-8116-9cf387a8033e<commit_after>c34b5e7d-327f-11e5-8116-9cf387a8033e<|endoftext|>
<commit_before>162439be-2f67-11e5-bb36-6c40088e03e4<commit_msg>162aba34-2f67-11e5-81b6-6c40088e03e4<commit_after>162aba34-2f67-11e5-81b6-6c40088e03e4<|endoftext|>
<commit_before>db4840d9-327f-11e5-b6a2-9cf387a8033e<commit_msg>db50b92b-327f-11e5-a555-9cf387a8033e<commit_after>db50b92b-327f-11e5-a555-9cf387a8033e<|endoftext|>
<commit_before>30d2c992-2f67-11e5-8632-6c40088e03e4<commit_msg>30d9410a-2f67-11e5-a57e-6c40088e03e4<commit_after>30d9410a-2f67-11e5-a57e-6c40088e03e4<|endoftext|>
<commit_before>7702f8a8-2d53-11e5-baeb-247703a38240<commit_msg>77037e54-2d53-11e5-baeb-247703a38240<commit_after>77037e54-2d53-11e5-baeb-247703a38240<|endoftext|>
<commit_before>e7216661-2747-11e6-a684-e0f84713e7b8<commit_msg>Put the thingie in the thingie<commit_after>e731fb1c-2747-11e6-9321-e0f84713e7b8<|endoftext|>
<commit_before>78c7f17a-2d53-11e5-baeb-247703a38240<commit_msg>78c874c4-2d53-11e5-baeb-247703a38240<commit_after>78c874c4-2d53-11e5-baeb-247703a38240<|endoftext|>
<commit_before>809e91e7-2d15-11e5-af21-0401358ea401<commit_msg>809e91e8-2d15-11e5-af21-0401358ea401<commit_after>809e91e8-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>a16d59a3-327f-11e5-9d33-9cf387a8033e<commit_msg>a1734530-327f-11e5-853e-9cf387a8033e<commit_after>a1734530-327f-11e5-853e-9cf387a8033e<|endoftext|>
<commit_before>/* --------------------------------------------------------------------------- ** This software is in the public domain, furnished "as is", without technical ** support, and with no warranty, express or implied, as to its usefulness for ** any purpose. ** ** main.cpp ** ** Simple Test Using live555helper ** -------------------------------------------------------------------------*/ #include <iostream> #include <fstream> #include <sstream> #include <map> #include <signal.h> #include "environment.h" #include "rtspconnectionclient.h" #include "sdpclient.h" #include "mkvclient.h" class RTSPCallback : public RTSPConnection::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: RTSPCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } virtual void onError(RTSPConnection& connection, const char* message) { std::cout << "Error:" << message << std::endl; connection.start(10); } virtual void onConnectionTimeout(RTSPConnection& connection) { std::cout << "Connection timeout -> retry" << std::endl; connection.start(); } virtual void onDataTimeout(RTSPConnection& connection) { std::cout << "Data timeout -> retry" << std::endl; connection.start(); } }; class SDPCallback : public SDPClient::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: SDPCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } virtual void onError(SDPClient& connection, const char* message) { std::cout << "Error:" << message << std::endl; } }; class MKVCallback : public MKVClient::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: MKVCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } }; char stop = 0; void sig_handler(int signo) { if (signo == SIGINT) { printf("received SIGINT\n"); stop = 1; } } void usage(const char* app) { std::cout << "Usage: " << app << " url" << std::endl; } int main(int argc, char *argv[]) { // default value int timeout = 10; int rtptransport = RTSPConnection::RTPUDPUNICAST; int logLevel = 255; std::string output; // decode args int c = 0; while ((c = getopt (argc, argv, "hv:" "t:o:" "MTH")) != -1) { switch (c) { case 'v': logLevel = atoi(optarg); break; case 'h': usage(argv[0]); return 0; case 't': timeout= atoi(optarg); break; case 'o': output = optarg; break; case 'M': rtptransport = RTSPConnection::RTPUDPMULTICAST; break; case 'T': rtptransport = RTSPConnection::RTPOVERTCP; break; case 'H': rtptransport = RTSPConnection::RTPOVERHTTP; break; } } if (optind<argc) { Environment env(stop); std::string url = argv[optind]; if (url.find("rtsp://") == 0) { RTSPCallback cb(output); RTSPConnection rtspClient(env, &cb, url.c_str(), timeout, rtptransport, logLevel); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } else if (url.find("file://") == 0) { MKVCallback cb(output); MKVClient mkvClient(env, &cb, url.c_str()); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } else { std::string sdp; if (url.find("rtp://") == 0) { std::istringstream is(url.substr(strlen("rtp://"))); std::string ip; std::getline(is, ip, ':'); std::string port; std::getline(is, port, '/'); std::string rtppayloadtype("96"); std::getline(is, rtppayloadtype, '/'); std::string codec("H264"); std::getline(is, codec); std::ostringstream os; os << "m=video " << port << " RTP/AVP " << rtppayloadtype << "\r\n" << "c=IN IP4 " << ip <<"\r\n" << "a=rtpmap:" << rtppayloadtype << " " << codec << "\r\n"; sdp.assign(os.str()); } else { std::ifstream is(url); sdp.assign((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>()); } std::cout << "SDP:\n" << sdp << std::endl; SDPCallback cb(output); SDPClient rtpClient(env, &cb, sdp.c_str()); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } } else { usage(argv[0]); } return 0; } <commit_msg>fix build<commit_after>/* --------------------------------------------------------------------------- ** This software is in the public domain, furnished "as is", without technical ** support, and with no warranty, express or implied, as to its usefulness for ** any purpose. ** ** main.cpp ** ** Simple Test Using live555helper ** -------------------------------------------------------------------------*/ #include <iostream> #include <fstream> #include <sstream> #include <map> #include <signal.h> #include "environment.h" #include "rtspconnectionclient.h" #include "sdpclient.h" #include "mkvclient.h" class RTSPCallback : public RTSPConnection::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: RTSPCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } virtual void onError(RTSPConnection& connection, const char* message) { std::cout << "Error:" << message << std::endl; connection.start(10); } virtual void onConnectionTimeout(RTSPConnection& connection) { std::cout << "Connection timeout -> retry" << std::endl; connection.start(); } virtual void onDataTimeout(RTSPConnection& connection) { std::cout << "Data timeout -> retry" << std::endl; connection.start(); } }; class SDPCallback : public SDPClient::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: SDPCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } virtual void onError(SDPClient& connection, const char* message) { std::cout << "Error:" << message << std::endl; } }; class MKVCallback : public MKVClient::Callback { private: std::map<std::string,std::ofstream> m_ofs; std::string m_fileprefix; public: MKVCallback(const std::string & output) : m_fileprefix(output) {} virtual bool onNewSession(const char* id, const char* media, const char* codec, const char*) { if (!m_fileprefix.empty()) { auto it = m_ofs.find(id); if (it == m_ofs.end()) { std::string filename = m_fileprefix + "_" + media + "_" + codec + "_" + id; m_ofs[id].open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); } } std::cout << id << " " << media << "/" << codec << std::endl; return true; } virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime) { std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl; auto it = m_ofs.find(id); if (it != m_ofs.end()) { it->second.write((char*)buffer, size); } return true; } }; char stop = 0; void sig_handler(int signo) { if (signo == SIGINT) { printf("received SIGINT\n"); stop = 1; } } void usage(const char* app) { std::cout << "Usage: " << app << " url" << std::endl; } int main(int argc, char *argv[]) { // default value int timeout = 10; int rtptransport = RTSPConnection::RTPUDPUNICAST; int logLevel = 255; std::string output; // decode args int c = 0; while ((c = getopt (argc, argv, "hv:" "t:o:" "MTH")) != -1) { switch (c) { case 'v': logLevel = atoi(optarg); break; case 'h': usage(argv[0]); return 0; case 't': timeout= atoi(optarg); break; case 'o': output = optarg; break; case 'M': rtptransport = RTSPConnection::RTPUDPMULTICAST; break; case 'T': rtptransport = RTSPConnection::RTPOVERTCP; break; case 'H': rtptransport = RTSPConnection::RTPOVERHTTP; break; } } if (optind<argc) { Environment env(stop); std::string url = argv[optind]; if (url.find("rtsp://") == 0) { RTSPCallback cb(output); RTSPConnection rtspClient(env, &cb, url.c_str(), timeout, rtptransport, logLevel); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } else if (url.find("file://") == 0) { MKVCallback cb(output); MKVClient mkvClient(env, &cb, url.c_str(), std::map<std::string,std::string>()); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } else { std::string sdp; if (url.find("rtp://") == 0) { std::istringstream is(url.substr(strlen("rtp://"))); std::string ip; std::getline(is, ip, ':'); std::string port; std::getline(is, port, '/'); std::string rtppayloadtype("96"); std::getline(is, rtppayloadtype, '/'); std::string codec("H264"); std::getline(is, codec); std::ostringstream os; os << "m=video " << port << " RTP/AVP " << rtppayloadtype << "\r\n" << "c=IN IP4 " << ip <<"\r\n" << "a=rtpmap:" << rtppayloadtype << " " << codec << "\r\n"; sdp.assign(os.str()); } else { std::ifstream is(url); sdp.assign((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>()); } std::cout << "SDP:\n" << sdp << std::endl; SDPCallback cb(output); SDPClient rtpClient(env, &cb, sdp.c_str()); signal(SIGINT, sig_handler); std::cout << "Start mainloop" << std::endl; env.mainloop(); } } else { usage(argv[0]); } return 0; } <|endoftext|>
<commit_before>76ada718-2d53-11e5-baeb-247703a38240<commit_msg>76ae2d96-2d53-11e5-baeb-247703a38240<commit_after>76ae2d96-2d53-11e5-baeb-247703a38240<|endoftext|>
<commit_before>8fd048d1-2d14-11e5-af21-0401358ea401<commit_msg>8fd048d2-2d14-11e5-af21-0401358ea401<commit_after>8fd048d2-2d14-11e5-af21-0401358ea401<|endoftext|>
<commit_before>f7404a3e-585a-11e5-90b9-6c40088e03e4<commit_msg>f746f6a4-585a-11e5-bfb8-6c40088e03e4<commit_after>f746f6a4-585a-11e5-bfb8-6c40088e03e4<|endoftext|>
<commit_before>9a6e403e-35ca-11e5-9e22-6c40088e03e4<commit_msg>9a74feb0-35ca-11e5-8169-6c40088e03e4<commit_after>9a74feb0-35ca-11e5-8169-6c40088e03e4<|endoftext|>
<commit_before>e0adf0d7-327f-11e5-8101-9cf387a8033e<commit_msg>e0b82968-327f-11e5-aab1-9cf387a8033e<commit_after>e0b82968-327f-11e5-aab1-9cf387a8033e<|endoftext|>
<commit_before>d6ad72ec-585a-11e5-9b59-6c40088e03e4<commit_msg>d6b42dc6-585a-11e5-8e69-6c40088e03e4<commit_after>d6b42dc6-585a-11e5-8e69-6c40088e03e4<|endoftext|>
<commit_before>65a045e4-2fa5-11e5-97d1-00012e3d3f12<commit_msg>65a268c6-2fa5-11e5-90e7-00012e3d3f12<commit_after>65a268c6-2fa5-11e5-90e7-00012e3d3f12<|endoftext|>
<commit_before>8431fc50-2d15-11e5-af21-0401358ea401<commit_msg>8431fc51-2d15-11e5-af21-0401358ea401<commit_after>8431fc51-2d15-11e5-af21-0401358ea401<|endoftext|>
<commit_before>#include <iostream> #include <string> #include <cstring> #include <cstdio> #include <map> #include <ei.h> using namespace std; class ConvertorChild { }; using ProcessTable = map<erlang_pid*, ConvertorChild>; //save_kcachegrind_format class Saver { FILE* real = nullptr; //output file bool merged; //options - save pid or not const unsigned spaces = 20; //enough to save 2^64 bits const char* header = "events: Time\n" \ "creator: C++ enhanced version of virtan/eep https://github.com/xbrukner/eep_cpp\n"\ "summary: "; const char* header_end = "\n\n"; std::string kcgfile(const char* filename) { std::string ret("callgrind.out"); ret.append(filename); return ret; } void save_header() { fprintf(real, "%s", header); for(unsigned i = 0; i < spaces; ++i) fputc(' ', real); fprintf(real, "%s", header_end); } //In-place header modification void modify_header(unsigned number) { string n = to_string(number); fseek(real, strlen(header) + spaces - n.size(), SEEK_SET); fprintf(real, "%s", n.c_str()); } unsigned p = 1; //messages unsigned minTime = 0; //now unsigned maxTime = 0; unsigned startTime = 0; //now const unsigned buffer_size = 20*1024*1024; unsigned buffer_filled = 0; char *buffer; unsigned stuck = 0; ProcessTable &processes; public: Saver(const char* filename, bool merged, ProcessTable& processes) : merged(merged), buffer(new char[buffer_size]), processes(processes) { //TODO - now into minTime and startTime real = fopen(kcgfile(filename).c_str(), "w+"); if (!real) { cerr << "Could not open output file" << endl; abort(); } save_header(); } ~Saver() { fclose(real); delete[] buffer; } }; class CallgrindConvertor { //Processes: ProcessTable processes; //Saver: Saver saver; //Options: bool waits; public: CallgrindConvertor(const char* filename, bool waits, bool merged) : saver(filename, merged, processes), waits(waits) { } }; int main(int argc, char** argv) { if (argc != 3) { cerr << "Usage: binary waits merged_pids" << endl; return 0; } bool waits = strcmp(argv[1], "true") == 0; bool merged = strcmp(argv[1], "true") == 0; } <commit_msg>Finish Saver.<commit_after>#include <iostream> #include <string> #include <cstring> #include <cstdio> #include <map> #include <ei.h> #include <chrono> #include <algorithm> #include <cassert> #include <cmath> using namespace std; class ConvertorChild { bool finalized = false; public: bool finalized_check() { if (finalized) return false; return finalized = true; } void finalize() { } }; using ProcessTable = map<erlang_pid*, ConvertorChild>; unsigned now_microseconds() { auto now = chrono::high_resolution_clock::now(); chrono::time_point<chrono::high_resolution_clock, chrono::microseconds> tp(chrono::time_point_cast<chrono::microseconds>(now)); return tp.time_since_epoch().count(); } unsigned td(unsigned from, unsigned to) { return to - from; } void finalize_processes(ProcessTable& table) { for(auto &i : table) { i.second.finalize(); } } //save_kcachegrind_format class Saver { FILE* real = nullptr; //output file const unsigned spaces = 20; //enough to save 2^64 bits const char* header = "events: Time\n" \ "creator: C++ enhanced version of virtan/eep https://github.com/xbrukner/eep_cpp\n"\ "summary: "; const char* header_end = "\n\n"; std::string kcgfile(const char* filename) { std::string ret("callgrind.out"); ret.append(filename); return ret; } void save_header() { fprintf(real, "%s", header); for(unsigned i = 0; i < spaces; ++i) fputc(' ', real); fprintf(real, "%s", header_end); } //In-place header modification void modify_header(unsigned number) { string n = to_string(number); fseek(real, strlen(header) + spaces - n.size(), SEEK_SET); fprintf(real, "%s", n.c_str()); } unsigned p = 1; //messages unsigned minTime = 0; //now unsigned maxTime = 0; unsigned startTime = 0; //now const unsigned buffer_size = 20*1024*1024; unsigned buffer_filled = 0; char *buffer; unsigned stuck = 0; ProcessTable &processes; unsigned finalizedCount = 0; //When finalized is called, this counter is increased void flush_buffer() { fwrite(buffer, buffer_filled, 1, real); buffer[0] = '\0'; buffer_filled = 0; } public: bool done = false; Saver(const char* filename, ProcessTable& processes) : buffer(new char[buffer_size]), processes(processes) { minTime = startTime = now_microseconds(); real = fopen(kcgfile(filename).c_str(), "w+"); if (!real) { cerr << "Could not open output file" << endl; abort(); } save_header(); } ~Saver() { fclose(real); delete[] buffer; } void receive_bytes(const string &bytes, unsigned ts) { if (bytes.size() + buffer_filled >= buffer_size) { flush_buffer(); } assert(bytes.size() + buffer_filled < buffer_size); //Packet is not too big strcpy(buffer + buffer_filled, bytes.c_str()); buffer_filled += bytes.size(); p++; minTime = min(minTime, ts); maxTime = max(maxTime, ts); stuck = 0; } void finalize(erlang_pid* pid, unsigned minTime1, unsigned maxTime1) { minTime = min(minTime, minTime1); maxTime = max(maxTime, maxTime1); if (processes[pid].finalized_check()) finalizedCount++; if (finalizedCount == processes.size()) { working_status(maxTime); flush_buffer(); modify_header(td(minTime, maxTime)); done = true; } } void status() { if (stuck >= 2) { working_status(max(minTime, maxTime)); std::cerr << "No end_of_trace and no data, finishing forcibly (" << processes.size() << ")" << endl; finalize_processes(processes); } else { working_status(max(minTime, maxTime)); } stuck++; } void working_status(unsigned max_time) { unsigned now = now_microseconds(); cerr << p << " msgs (" << round(p / (td(startTime, now) / 1000000)) << " msgs/sec), " << td(minTime, max_time) / 1000000 << " secs (" << round(td(startTime, now) / max(td(minTime, max_time), 1u)) << "x slowdown)" << endl; } }; class CallgrindConvertor { //Processes: ProcessTable processes; //Saver: Saver saver; //Options: bool waits; bool merged; public: CallgrindConvertor(const char* filename, bool waits, bool merged) : saver(filename, processes), waits(waits), merged(merged) { } }; int main(int argc, char** argv) { if (argc != 3) { cerr << "Usage: binary waits merged_pids" << endl; return 0; } bool waits = strcmp(argv[1], "true") == 0; bool merged = strcmp(argv[1], "true") == 0; } <|endoftext|>
<commit_before>99a1a846-35ca-11e5-8bd0-6c40088e03e4<commit_msg>99a88e7a-35ca-11e5-ba6f-6c40088e03e4<commit_after>99a88e7a-35ca-11e5-ba6f-6c40088e03e4<|endoftext|>
<commit_before>5e907588-5216-11e5-bd15-6c40088e03e4<commit_msg>5e978c74-5216-11e5-b822-6c40088e03e4<commit_after>5e978c74-5216-11e5-b822-6c40088e03e4<|endoftext|>
<commit_before>d2e71a0f-313a-11e5-9eed-3c15c2e10482<commit_msg>d2eceef3-313a-11e5-945b-3c15c2e10482<commit_after>d2eceef3-313a-11e5-945b-3c15c2e10482<|endoftext|>
<commit_before>e9652bd7-313a-11e5-b5e4-3c15c2e10482<commit_msg>e96e3278-313a-11e5-8d9b-3c15c2e10482<commit_after>e96e3278-313a-11e5-8d9b-3c15c2e10482<|endoftext|>
<commit_before>cb4c94ba-35ca-11e5-b3ff-6c40088e03e4<commit_msg>cb52e9fa-35ca-11e5-99bc-6c40088e03e4<commit_after>cb52e9fa-35ca-11e5-99bc-6c40088e03e4<|endoftext|>