repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
npruehs/block-burst
Source/BlockBurst/BlockBurst/BlockBurst.Shared/Block.h
<gh_stars>0 #pragma once using namespace DirectX; namespace BlockBurst { enum BlockType { Good, Bad, Dead }; struct Block { XMFLOAT3 position; XMFLOAT3 velocity; float rotation; VertexPositionColor vertices[8]; int indexOffset; BlockType blockType; float size; }; }
npruehs/block-burst
Source/BlockBurst/BlockBurst/BlockBurst.Shared/BlockBurstMain.h
#pragma once #include "Common\StepTimer.h" #include "Common\DeviceResources.h" #include "Content\Sample3DSceneRenderer.h" #include "Content\ScoreTextRenderer.h" #include "Block.h" // Renders Direct2D and 3D content on the screen. namespace BlockBurst { class BlockBurstMain : public DX::IDeviceNotify { public: BlockBurstMain(const std::shared_ptr<DX::DeviceResources>& deviceResources); ~BlockBurstMain(); void CreateWindowSizeDependentResources(); void Update(); bool Render(); void OnTap(float screenPositionX, float screenPositionY); int GetScore(); // IDeviceNotify virtual void OnDeviceLost(); virtual void OnDeviceRestored(); private: // Cached pointer to device resources. std::shared_ptr<DX::DeviceResources> m_deviceResources; // TODO: Replace with your own content renderers. std::unique_ptr<Sample3DSceneRenderer> m_sceneRenderer; std::unique_ptr<ScoreTextRenderer> scoreTextRenderer; // Rendering loop timer. DX::StepTimer m_timer; bool initialized; // Blocks in the scene. std::shared_ptr<std::vector<Block>> blocks; // Game difficulty. Affects velocity of blocks. float difficulty; // Time until next block is spawned, in seconds. float spawnTimeRemaining; // Points scored by collecting blocks. int score; // Creates a new block at the specified position and adds it to the scene to be rendered. void CreateBlock(XMFLOAT3 position, float size, BlockType blockType); }; }
npruehs/block-burst
Source/BlockBurst/BlockBurst/BlockBurst.Shared/Content/Sample3DSceneRenderer.h
#pragma once #include "..\Common\DeviceResources.h" #include "ShaderStructures.h" #include "..\Common\StepTimer.h" #include "../Block.h" namespace BlockBurst { // This sample renderer instantiates a basic rendering pipeline. class Sample3DSceneRenderer { public: Sample3DSceneRenderer(const std::shared_ptr<DX::DeviceResources>& deviceResources); void CreateDeviceDependentResources(); void CreateWindowSizeDependentResources(); void ReleaseDeviceDependentResources(); void Update(DX::StepTimer const& timer); void Render(); bool IsInitialized(); // Re-builds the GPU vertex and index buffers for the scene. void BuildGPUBuffers(std::shared_ptr<std::vector<Block>> blocks); private: void Rotate(float radians); // Cached pointer to device resources. std::shared_ptr<DX::DeviceResources> m_deviceResources; std::shared_ptr<std::vector<Block>> blocks; // Direct3D resources for cube geometry. Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout; Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer; Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader; Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader; Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer; // System resources for cube geometry. ModelViewProjectionConstantBuffer m_constantBufferData; uint32 m_indexCount; // Variables used with the rendering loop. bool m_loadingComplete; float m_degreesPerSecond; // Vertices of this scene to be rendered. std::vector<VertexPositionColor> vertices; // Triangle list of vertices of this scene to be rendered. std::vector<unsigned short> indices; }; }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/clock.c
#include "pins.h" #include "LCD1602.h" #include "DS1302.h" #include "DS18B20.h" #include "EEPROM.h" //Sytem variable, time, state, flag. //--------------------------- enum system_state {DEFAULT, SETTING}; //Define the system state. enum system_state present_state; unsigned char cursor_index; //Define the current setting index. struct time_and_date SetTime; //Store the set time. struct time_and_date CurTime; //Store the current time. bit mute_flag = 0; //Mute flag, if mute set to 1 else set to 0. //unsigned char present_minute; //Store the current second, to sense the hour. //unsigned char present_second; //Store the curretn second, to sense the alarm. int present_temper = 0; //Store the current temperature, to sense the alarm. bit uart_flag = 0; //Make sure if uart start,if start set to 1, else set to 0. bit rd_flag = 1; //Test if send temperature or date. 0 send data, 1 send temp. bit real_time = 1; unsigned char temp_counter = 0; //bit forbid_song = 0; //Since song and uart both use timer1 so when send the data we can not have alarm. unsigned char uart_i= 0; //Index of UART. //unsigned char buf[1]; //--------------------------- //Infrared variable, only used in infrared module. //--------------------------- bit ir_finish = 0; //Ir flag if recieved data, set to 1, else set to 0. unsigned char ir_data[4]; //Data buffer since there are 4 bytes need to be recieved. const uint8 code ir_map[][2] = { {0x45,'s'}, {0x46,'o'}, {0x47,'m'}, //shutdown Mode Mute {0x44,'u'}, {0x40,'l'}, {0x43,'r'}, //unknown left Right {0x07,'e'}, {0x15,'d'}, {0x09,'i'}, // EQ Inc Dec {0x16,'0'}, {0x19,'x'}, {0x0D,'y'}, //'0'->'0' RPT U/SD {0x0C,'1'}, {0x18,'2'}, {0x5E,'3'}, //'1'->'1' '2'->'2' '3'->'3' {0x08,'4'}, {0x1C,'5'}, {0x5A,'6'}, //'4'->'4' '5'->'5' '6'->'6' {0x42,'7'}, {0x52,'8'}, {0x4A,'9'}, //'7'->'7' '6'->'8' '9'->'9' }; //--------------------------- //Varaible use for song module only. //--------------------------- code unsigned char FH[] = { //Initila value for timer1 high eight bits 0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8, //Low frequency 0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC, //Medium freqency. 0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFE, //High frequency. 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF //Super high freqency. }; code unsigned char FL[] = { //Initila value for timer1 low eight bits 0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, //Low frequency 0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, //Medium freqency. 0x8F,0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, //High frequency. 0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16 //Super high freqency. }; code unsigned char song_code[] = { //The code of shi shang zhi you mama hao. 6, 2, 3, 5, 2, 1, 3, 2, 2, 5, 2, 2, 1, 3, 2, 6, 2, 1, 5, 2, 1,6, 2, 4, 3, 2, 2, 5, 2, 1, 6, 2, 1, 5, 2, 2, 3, 2, 2, 1, 2, 1,6, 1, 1, 5, 2, 1, 3, 2, 1, 2, 2, 4, 2, 2, 3, 3, 2, 1, 5, 2, 2,5, 2, 1, 6, 2, 1, 3, 2, 2, 2, 2, 2, 1, 2, 4, 5, 2, 3, 3, 2, 1,2, 2, 1, 1, 2, 1, 6, 1, 1, 1, 2, 1, 5, 1, 6, 0, 0, 0 }; unsigned char song_timer1_high = 0; //High eight bits for timer1. unsigned char song_timer1_low = 0; //Low eight bits for timer1. unsigned char song_time = 1; //------------------------------- //Function definition. void song_begin(void); void song_delay(unsigned char t); void show_time(struct time_and_date *tim); void show_temp(); void eeprom_store_time(struct time_and_date *tim); void ir_key_serve(void); void ir_init(void); void number_setting(unsigned char opcode); void cursor_shift_right(); void cursor_shift_left(); void cancel_set(); void state_transition(); void key_act(unsigned char key_op); void timer_config(void); /*** Infrared module. Using timer0 to calculate the delay. Using the external interrupt 0 to sense the input signal. Here we need to change the mode of TMOD so we may change the mode of timer1 need to cauciouse. Global variable: ir_flag: check if finished recieve if done set to 1. ir_data: store the recieved data, the third value is what we want. ***/ //------------------------------------------------------------------------------------- void ir_delay(unsigned int i) { while(i--); } //Use the key serve function to change the state of void ir_key_serve(void){ unsigned char i = 0; if(ir_finish){ ir_finish = 0; for (i = 0; i < 21; i++) { if(ir_data[2] == ir_map[i][0]) { //lcd_set_cursor(13,0); //lcd_write_data(ir_map[i][1]); //lcd_show_string(0,13, ir_map[i][1]); key_act(ir_map[i][1]); break; } } } } //Init the infrared equipment. void ir_init(void) { IR_DATA = 1; //To prepare read the value. TMOD = 0x11; TH0 = 0x00; TL0 = 0x00; ET1 = 1; EA = 1; //Open the global interrupt ET0 = 0; //Forbid the timer0 interrupt TR0 = 0; //Shut down the timer0. IT0 = 1; //Open the external interrupt0 EX0 = 1; //Using the edge triger. } //Get the low voltage time. unsigned int ir_get_high_time(){ TH0 = 0; TL0 = 0; TR0 = 1; //Open the timer 0 while(IR_DATA) { //Get the low time if (TH0 > 0X40) //To prevent the wrong condition break if takes too long. break; } TR0 = 0; //Shut down the timer0. return (TH0*256 + TL0); } //Get the high voltage time. unsigned int ir_get_low_time() { TH0 = 0; TL0 = 0; TR0 = 1; while(!IR_DATA){ if (TH0 > 0x40) break; } TR0 = 0; return (TH0*256 + TL0); } //Interrupt0 serve function. Get the data. void ir_get_data() interrupt 0 { unsigned char i, j = 0; unsigned char recieved_byte; unsigned int tmp; tmp = ir_get_low_time(); if((tmp < 7000) || (tmp > 10000)) { //Get the first 9ms IE0 = 0; return; } tmp = ir_get_high_time(); //Get the low 4.5ms if((tmp < 3500) || (tmp > 5000)) { IE0 = 0; return; } for(i = 0; i < 4; i++){ for(j = 0;j < 8; j++) { tmp = ir_get_low_time(); //Get the 560us low voltage. if((tmp < 310) || (tmp > 720)) { IE0 = 0; return; } tmp = ir_get_high_time(); if ((tmp > 310) && (tmp < 720)) { //If the time between 1460us to 1900us. set 1 else set 0. recieved_byte >>= 1; } else if ((tmp > 1300)&&(tmp < 1800)) { recieved_byte >>= 1; recieved_byte |= 0x80; } else { //If not at that scope exist. IE0 = 0; return; } } ir_data[i] = recieved_byte; } ir_finish = 1; //Finish recieve. IE0 = 0; } //------------------------------------------------------------------------------------- //Function for singing a song: <NAME> you <NAME>. //Here using timer1 to calculate delay. //------------------------------------------------------------------------------------- void song_delay(unsigned char t) { unsigned char i; unsigned long j; if ((mute_flag == 0)){ for(i=0;i<t;i++) for(j=0;j<8000;j++); TR1 = 0; } else { TR1 = 0; return; } } void song_begin(void){ unsigned char i,m = 0; //TMOD = 0x11; //ET1 = 1; if((mute_flag == 0)) { //If mute flag is 1, break the loop. EA = 1; i = 0; m = 0; //TMOD = 0x11; song_time = 1; while(song_time) { m = song_code[i] + 7*song_code[i+1] - 1; song_timer1_high = FH[m]; song_timer1_low = FL[m]; song_time = song_code[i+2]; i+=3; TH1 = song_timer1_high; TL1 = song_timer1_low; TR1 = 1; song_delay(song_time); } } else { return; } } //------------------------------------------------------------------------------------- //Some interrupt functions. //------------------------------------------------------------------------------------- void Timer0Interrupt(void) interrupt 1 //Timer0's interrupt. { } void Timer1Interrupt(void) interrupt 3 //Timer1's interrupt. { if(uart_flag == 0) { TR1 = 0; BEEM = !BEEM; TH1 = song_timer1_high; TL1 = song_timer1_low; TR1 = 1; } } void interruptUART() interrupt 4{ unsigned char a; if (RI) { RI = 0; //Clear RI manually. a = SBUF; SBUF = a; } if (TI) { TI = 0; //Clear TI manually if (real_time == 1) { SBUF = CurTime.TimeString[uart_i]; } else { SBUF = SetTime.TimeString[uart_i]; } uart_i++; if (uart_i >9) //SBUF = ' '; uart_i = 0; } } void Timer2_Server(void) interrupt 5 //Timer2's interrupt. { static unsigned char Timer2_Server_Count; RCAP2H= 0x3C; RCAP2L= 0x0B0; Timer2_Server_Count++; if(Timer2_Server_Count==10) { Timer2_Server_Count=0; TF2=0; ir_key_serve(); if (present_state == DEFAULT){ lcd_close_cursor(); ds1302_get_time(&CurTime); ds1302_date_to_str (&CurTime); ds1302_time_to_str(&CurTime); lcd_show_string(0, 1, CurTime.DateString); lcd_show_string(8, 1, CurTime.TimeString); lcd_set_cursor(11, 0); lcd_write_data((CurTime.week & 0x0F) + '0'); if(rd_flag == 0 && uart_flag == 1){ eeprom_write_multi(CurTime.TimeString, 0x00, 8); } else if (uart_flag == 1 && rd_flag == 1){ eeprom_read_multi(SetTime.TimeString, 0x00, 8); } } } temp_counter++; if (temp_counter == 20) { if (present_state == DEFAULT){ show_temp(); } temp_counter = 0; } } //------------------------------------------------------------------------------------- //Display function. & Store value function. //------------------------------------------------------------------------------------- void show_temp() { int temper = 0; unsigned char str[5]; unsigned char a,b; a = ds18b20_get_temp(&temper); b = ds18b20_start_transition(); temper >>= 4; present_temper = temper; str[0] = (temper/10) + '0'; str[1] = (temper%10) + '0'; str[2] = '\''; str[3] = 'C'; str[4] = '\0'; lcd_show_string(0,0,"T:"); lcd_show_string(2,0,str); } //Show some static string. So we don not need to refresh it. void show_init() { lcd_clear_screen(); lcd_show_string(0, 0, "T:"); lcd_show_string(4, 0, "'C"); lcd_show_string(7, 0, "week"); lcd_close_cursor(); if(mute_flag == 1){ lcd_show_string(13,0,"Mut"); } else { lcd_show_string(13,0,"Dis"); } } void eeprom_store_time(struct time_and_date *tim) { unsigned char buffer[6]; buffer[0] = 0x2018; buffer[1] = 0x11; buffer[2] = 0x27; buffer[3] = 0x12; buffer[4] = 0x00; buffer[5] = tim->second; eeprom_write_multi(buffer, 0x30, 6); } //------------------------------------------------------------------------------------- //Main function some initialize. //------------------------------------------------------------------------------------- void main(void) { //unsigned char buf[6]; unsigned char i = 0; IT0=1; EX0=1; EA=1; IR_DATA=1; lcd_init(); ds1302_init(); ds18b20_start_transition(); ds1302_get_time(&SetTime); eeprom_store_time(&SetTime); //delayms(30); RCAP2H= 0x3C; RCAP2L= 0x0B0; ET2=1; EA=1; TR2=1; ir_init(); show_init(); while(1){ if (((CurTime.minute >> 4) == 0) && ((CurTime.minute & 0x0F) == 0) && ((CurTime.second >> 4) == 0) && ((CurTime.second & 0x0F) <= 1)) { if ((mute_flag == 0)) { song_begin(); } } else if((present_temper/10>=2) && (present_temper%10>=8)){ if((mute_flag == 0)) song_begin(); } } } //------------------------------------------------------------------------------------- //Key action and state transition function. //------------------------------------------------------------------------------------- //Acting when dectect key was pressed. void key_act(unsigned char key_op) { if((key_op >= '0') && (key_op <= '9')) { number_setting(key_op); } else if (key_op == 'r') { //Set cursor right, when right key was pressed. cursor_shift_right(); } else if(key_op == 'l') { //Set cursor left, when left key was pressed cursor_shift_left(); } else if(key_op == 'o') { //Change the state of the system. when mode key was pressed. state_transition(); } else if(key_op == 'm') { //Change the state to mute state, if mute key was pressed. if (present_state == DEFAULT) { //If the current state is default state just mute the song. mute_flag = ~mute_flag; if(mute_flag == 1){ lcd_show_string(13,0,"Mut"); } else { lcd_show_string(13,0,"Dis"); } } else { cancel_set(); //else cancel the current setting. } } else if(key_op == 'y') { uart_flag = ~uart_flag; //mute_flag = 1; if(uart_flag == 1) { lcd_show_string(13,0,"UAR"); } else if (mute_flag == 1){ lcd_show_string(13,0,"Mut"); } else if(mute_flag == 0) { lcd_show_string(13,0,"Dis"); } timer_config(); } else if (key_op == 'x') { if (rd_flag == 0 && uart_flag == 1) { lcd_show_string(13,0,"EWR"); } else if (rd_flag == 1 && uart_flag == 1) { lcd_show_string(13,0,"ERD"); } rd_flag = ~rd_flag; } else if (key_op == 'e') { real_time = ~real_time; } } void state_transition() { if (present_state == DEFAULT) { present_state = SETTING; //Change the current state to setting time state. SetTime.hour = CurTime.hour; //Store the current time to buffer. SetTime.minute = CurTime.minute; SetTime.second = CurTime.second; SetTime.week = CurTime.week; SetTime.year = CurTime.year; SetTime.month = CurTime.month; SetTime.day = CurTime.day; lcd_show_string(13,0,"SET"); cursor_index = 20; //Set the cursor when user press the key it will set at most left location cursor_shift_right(); lcd_open_cursor(); //Open the cursor. } else if(present_state == SETTING) { present_state = DEFAULT; //Set the present state to the default state. ds1302_set_time(&SetTime); //Give the setting time to ds1302. Updata the time. lcd_close_cursor(); if(mute_flag == 1){ lcd_show_string(13,0,"Mut"); } else { lcd_show_string(13,0,"Dis"); } } } //Cancel the current setting,if user press the mute key at setting state. void cancel_set() { present_state = DEFAULT; lcd_close_cursor(); lcd_clear_screen(); lcd_show_string(7, 0, "week"); ds1302_date_to_str (&CurTime); //Write the setting time to lcd. ds1302_time_to_str(&CurTime); lcd_show_string(0, 1, CurTime.DateString); lcd_show_string(8, 1, CurTime.TimeString); lcd_set_cursor(11, 0); lcd_write_data((CurTime.week & 0x0F) + '0'); if(mute_flag == 1){ lcd_show_string(13,0,"Mut"); } else { lcd_show_string(13,0,"Dis"); } show_temp(); } void timer_config(void) { if(uart_flag) { TMOD = 0x21; //Timer1 8 auto, Timer0,16 bit timer. SCON = 0x50; PCON = 0x00; TH1 = 0xE6; TL1 = TH1; EA = 1; ET1 = 0; ES = 1; TR1 = 1; } else { TMOD = 0X11; TH1 = 0; TL1 = 0; EA = 1; ET1 = 1; ES = 0; TR1 = 0; } } //------------------------------------------------------------------------------------- //Set operation function, set number, shift left, shift right. //------------------------------------------------------------------------------------- void cursor_shift_right() { if(present_state == SETTING) { //lcd_open_cursor(); switch (cursor_index) { case 0: cursor_index = 1; lcd_set_cursor(0,1); break; //Year second position case 1: cursor_index = 2; lcd_set_cursor(1,1); break; //Month first position case 2: cursor_index = 3; lcd_set_cursor(3,1); break; //Month first position case 3: cursor_index = 4; lcd_set_cursor(4,1); break; //Day first position case 4: cursor_index = 5; lcd_set_cursor(6,1); break; //Day second position. case 5: cursor_index = 6; lcd_set_cursor(7,1); break; //Hour first position. case 6: cursor_index = 7; lcd_set_cursor(8,1); break; //Hour second position. case 7: cursor_index = 8; lcd_set_cursor(9,1); break; //Minute first position. case 8: cursor_index = 9; lcd_set_cursor(11,1); break; //Minute second position. case 9: cursor_index = 10; lcd_set_cursor(12,1); break; //Second first position. case 10: cursor_index = 11; lcd_set_cursor(14,1); break;//Second second position. case 11: cursor_index = 12; lcd_set_cursor(15,1); break;//Week position. default: cursor_index = 0; lcd_set_cursor(11,0); break; //Back to begin. } } } void cursor_shift_left() { //lcd_open_cursor(); if(present_state == SETTING) { switch (cursor_index) { case 0: cursor_index = 12; lcd_set_cursor(15,1); break; case 1: cursor_index = 0; lcd_set_cursor(11,0); break; case 2: cursor_index = 1; lcd_set_cursor(0,1); break; case 3: cursor_index = 2; lcd_set_cursor(1,1); break; case 4: cursor_index = 3; lcd_set_cursor(3,1); break; case 5: cursor_index = 4; lcd_set_cursor(4,1); break; case 6: cursor_index = 5; lcd_set_cursor(6,1); break; case 7: cursor_index = 6; lcd_set_cursor(7,1); break; case 8: cursor_index = 7; lcd_set_cursor(8,1); break; case 9: cursor_index = 8; lcd_set_cursor(9,1); break; case 10: cursor_index = 9; lcd_set_cursor(11,1); break; case 11: cursor_index = 10; lcd_set_cursor(12,1); break; default: cursor_index = 11; lcd_set_cursor(14,1); break; } } } void number_setting(unsigned char opcode) { unsigned char numb = 0; numb = opcode - '0'; //lcd_open_cursor(); if(numb <= 9) { if (present_state == SETTING) { //Only change when we are at setting mode. switch (cursor_index) { case 0: { if (numb>7) numb = 7; SetTime.week = (SetTime.week&0xF0)|(numb); lcd_show_char(11,0,opcode); break; }; case 1: SetTime.year = (SetTime.year&0xFF0F)|(numb << 4); lcd_show_char(0,1,opcode); break; case 2: SetTime.year = (SetTime.year&0xFFF0)|(numb); lcd_show_char(1,1,opcode); break; case 3: SetTime.month = (SetTime.month&0x0F)|(numb<<4); lcd_show_char(3,1,opcode); break; case 4: SetTime.month = (SetTime.month&0xF0)|(numb); lcd_show_char(4,1,opcode); break; case 5: SetTime.day = (SetTime.day&0x0F)|(numb<<4); lcd_show_char(6,1,opcode); break; case 6: SetTime.day = (SetTime.day&0xF0)|(numb); lcd_show_char(7,1,opcode); break; case 7: SetTime.hour = (SetTime.hour&0x0F)|(numb<<4); lcd_show_char(8,1,opcode); break; case 8: SetTime.hour = (SetTime.hour&0xF0)|(numb); lcd_show_char(9,1,opcode); break; case 9: SetTime.minute = (SetTime.minute&0x0F)|(numb<<4); lcd_show_char(11,1,opcode); break; case 10: SetTime.minute = (SetTime.minute&0xF0)|(numb); lcd_show_char(12,1,opcode); break; case 11: SetTime.second = (SetTime.second&0x0F)|(numb<<4); lcd_show_char(14,1,opcode); break; default: SetTime.second = (SetTime.second&0xF0)|(numb); lcd_show_char(15,1,opcode); break; } } cursor_shift_right(); //Shift to right automatically. } } //-------------------------------------------------------------------------------------
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/SONG.c
#define _SONG_C #include "pins.h" #include "SONG.h" //Using timer1 to play song. void song_delay(unsigned char t) { unsigned char i,j; for(i=0;i<t;i++) for(j=0;j<8200;j++); TR1 = 1; } void song_begin(void){ unsigned char song_time = 1; unsigned char i,k = 0; TMOD = 0x10; TH1 = 0x00; TL1 = 0x00; EA = 1; ET1 = 1; while(song_time) { k = song_code[i] + 7*song_code[i+1] - 1; song_timer1_high = FH[k]; song_timer1_low = FL[k]; song_time = song_code[i+2]; i+=3; TH1 = song_timer1_high; TL1 = song_timer1_LOW; TR1 = 1; song_delay(song_time); } }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/LCD1602.h
#ifndef _LCD1602_H #define _LCD1602_H #ifndef _LCD1602_C //External varaible defined at here. #endif //External function defined at here. void lcd_write_cmd(unsigned char command); void lcd_write_data(unsigned char dat); void lcd_set_cursor(unsigned char x, unsigned char y); void lcd_show_string(unsigned char x, unsigned char y, unsigned char *strs); void lcd_clear_screen(void); void lcd_close_cursor(void); void lcd_open_cursor(void); void lcd_ready(void); void lcd_init(void); void lcd_show_char(unsigned char x, unsigned char y, unsigned char tmp1); #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/DS18B20.c
<reponame>lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051- #define _DS18B20_C #include "pins.h" #include "DS18B20.h" //Delay 10us, input is how many times of 10us for instance x=5, delay 50us. void delay10us(unsigned char x) { unsigned char i = 0; for(i=0;i<x;i++) { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } } //Write one byte to DS18B20 void ds18b20_write_byte(unsigned char dat) { unsigned char i = 0; unsigned char tmp = 0; tmp = dat; EA = 0; //Shut down the global interrupt, since DS18B20 need a strict time sequential. for (i=0;i<8;i++){ DS18B20_IO = 0; //Pull down IO 2us first. _nop_(); _nop_(); DS18B20_IO = tmp&0x01; //Send one bit data. delay10us(6); DS18B20_IO = 1; //Delay 60us for DS18B20 to read. tmp >>= 1; //Send next bit. } EA = 1; } //Read one byte from DS18B20. unsigned char ds18b20_read_byte() { unsigned char dat, i; EA = 0; //Shut down the global interrupt, since DS18B20 need a strict time sequential. for (i = 0x01; i != 0; i<<=1) { DS18B20_IO = 0; //Pull down IO 2us first. _nop_(); _nop_(); DS18B20_IO = 1; //Pull up IO 2us first. _nop_(); _nop_(); if(DS18B20_IO) //Read the value of DS18B20_IO dat = dat | i; //If value equal to 1 set the corresponding bit of dat to 1. else dat = dat & (~i); //If value equal to 0 set the corresponding bit of dat to 0. delay10us(6); } EA = 1; //Open the global interrupt. return dat; } //Get the real time temperature from DS18B20, input is a pointer. bit ds18b20_get_temp(int *temperature) { unsigned char low, high; bit acknowlegement = 1; //Get the acknowlegement of DS18B20, if there exist, we will get 0, if not we will get 1. EA = 0; DS18B20_IO = 0; delay10us(50); DS18B20_IO = 1; delay10us(6); acknowlegement = DS18B20_IO; while(!DS18B20_IO); EA = 1; if(acknowlegement == 0) { ds18b20_write_byte(0xCC); //Write 0xCC to skip the rom operation. ds18b20_write_byte(0xBE); //Write 0xBE to send the read operation. low = ds18b20_read_byte(); //Read the lsb of the temperature. high = ds18b20_read_byte(); //Read the msb of the temperature. *temperature = ((int)high << 8) + low; //Return the value using the pointer, total 16 bits. } return ~acknowlegement; //If get the value successfully, return 1, else return 0. } //Start the transition of DS18B20. bit ds18b20_start_transition() { bit acknowlegement = 1; //Get the acknowlegement of DS18B20, if there exist, we will get 0, if not we will get 1. EA = 0; DS18B20_IO = 0; delay10us(50); DS18B20_IO = 1; delay10us(6); acknowlegement = DS18B20_IO; while(!DS18B20_IO); EA = 1; if(acknowlegement == 0) { ds18b20_write_byte(0xCC); //Write 0xCC to skip the rom operation. ds18b20_write_byte(0x44); //Start the temperature transition. } return ~acknowlegement; //If get the value successfully, return 1, else return 0. }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/LCD1602.c
<gh_stars>0 #define _LCD1602_C #include "pins.h" #include "LCD1602.h" void Delay(unsigned char x) { unsigned int i,j; for(i=x;i>0;i--) { for(j=120;j>0;j--) {} } } //Check if LCD is ready, assistant function. void lcd_ready(void){ unsigned char a; P0 = 0xff; //To read the busy pin, set 1 first LCD_RS = 0; LCD_RW = 1; do { LCD_E = 1; //Need a low to high signal. a = LCD_DATA; //Read the condition bit. //Delay(5); LCD_E = 0; } while (a&0x80);//Stuck at here untill LCD ready. } //Write a commond to LCD. Exposed to outside. void lcd_write_cmd(unsigned char command){ lcd_ready(); LCD_RS = 0; LCD_RW = 0; LCD_E = 0; LCD_DATA = command; LCD_E = 1; _nop_(); _nop_(); LCD_E = 0; } //Write data to LCD. Exposed to outside. void lcd_write_data(unsigned char dat) { lcd_ready(); LCD_RS = 1; LCD_RW = 0; LCD_E = 0; LCD_DATA = dat; LCD_E = 1; _nop_(); _nop_(); LCD_E = 0; } //Set the cursor of LCD.Set the cursor at (x,y) void lcd_set_cursor(unsigned char x, unsigned char y){ unsigned char ad = 0; if(y == 0){ ad = 0x00 + x; } else { ad = 0x40 + x; } lcd_write_cmd(ad | 0x80); } //Show string at the LCD where start at (x,y) void lcd_show_string(unsigned char x, unsigned char y, unsigned char *strs){ lcd_set_cursor(x, y); while (*strs != '\0') { //If do not reach the end of string, write data. lcd_write_data(*strs++); //strs++; } } //Clear the whole LCD. void lcd_clear_screen(void) { lcd_write_cmd(0x01); } //Close the cursor of LCD. void lcd_close_cursor(void) { lcd_write_cmd(0x0C); } //Open the cursor of LCD. void lcd_open_cursor(void) { lcd_write_cmd(0x0F); } //Init the LCD void lcd_init(void){ lcd_write_cmd(0x38); //16*2 dispaly, 5*7 dot matrix, 8 parralel data path. lcd_write_cmd(0x0C); //Open the LCD, close the cursor. lcd_write_cmd(0x06); //Char stay, address increment automatically. lcd_write_cmd(0x01); //Clear the LCD. } //Show one char to lcd void lcd_show_char(unsigned char x, unsigned char y, unsigned char tmp1) { lcd_set_cursor(x, y); lcd_write_data(tmp1); }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/DS1302.h
<reponame>lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-<gh_stars>0 #ifndef _DS1302_H #define _DS1302_H //Struct to store the time of date of the whole program. struct time_and_date { unsigned int year; unsigned char month; unsigned char day; unsigned char hour; unsigned char minute; unsigned char second; unsigned char week; unsigned char DateString[9]; unsigned char TimeString[9]; }; #ifndef _DS1302_C #endif //Function define in the DS1302.C, API of DS1302. void ds1302_write_byte(unsigned char reg, unsigned char dat); unsigned char ds1302_read_byte(unsigned char reg); void ds1302_burst_write(unsigned char *dat); void ds1302_burst_read(unsigned char *dat); void ds1302_get_time(struct time_and_date *tim); void ds1302_set_time(struct time_and_date *tim); void ds1302_init(void); void ds1302_date_to_str (struct time_and_date *Time); void ds1302_time_to_str(struct time_and_date *Time); #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/IR.h
#ifndef _IR_H #define _IR_H #ifndef _IR_C #endif //Define the IR function at here.Using the timer0 to calculate the time. void ir_init(void); #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/IR.c
#define _IR_C #include "pins.h" #include "IR.h" struct time_and_date SetTime; bit ir_finish = 0; //Ir flag if recieved data, set to 1, else set to 0. unsigned char ir_data[4]; //Data buffer since there are 4 bytes need to be recieved. const uint8 code ir_map[][2] = { //???????PC?????? {0x45,0x00}, {0x46,0x00}, {0x47,0x1B}, //??->? Mode->? ??->ESC {0x44,0x00}, {0x40,0x25}, {0x43,0x27}, //??->? ??->?? ??->?? {0x07,0x00}, {0x15,0x28}, {0x09,0x26}, // EQ->? ??->?? ??->?? {0x16, '0'}, {0x19,0x1B}, {0x0D,0x0D}, //'0'->'0' ??->ESC U/SD->?? {0x0C, '1'}, {0x18, '2'}, {0x5E, '3'}, //'1'->'1' '2'->'2' '3'->'3' {0x08, '4'}, {0x1C, '5'}, {0x5A, '6'}, //'4'->'4' '5'->'5' '6'->'6' {0x42, '7'}, {0x52, '8'}, {0x4A, '9'}, //'7'->'7' '6'->'8' '9'->'9' }; //Init the infrared equipment. void ir_init(void) { IR_DATA = 1; //To prepare read the value. TMOD = 0x01; TH0 = 0x00; TL0 = 0x00; EA = 1; //Open the global interrupt ET0 = 0; //Forbid the timer0 interrupt TR0 = 0; //Shut down the timer0. IT0 = 1; //Open the external interrupt0 EX0 = 1; //Using the edge triger. } //Get the low voltage time. unsigned int ir_get_high_time(){ TH0 = 0; TL0 = 0; TR0 = 1; //Open the timer 0 while(!IR_DATA) { //Get the low time if (TH0 > 0X40) //To prevent the wrong condition break if takes too long. break; } TR0 = 0; //Shut down the timer0. return (TH0*256 + TL0); } //Get the high voltage time. unsigned int ir_get_low_time() { TH0 = 0; TL0 = 0; TR0 = 1; while(IR_DATA){ if (TH0 > 0x40) break; } TR0 = 0; return (TH0*256 + TL0); } //Interrupt0 serve function. Get the data. void ir_get_data() interrupt 0 { unsigned char i, j = 0; unsigned char recieved_byte; unsigned int tmp; tmp = ir_get_low_time(); if((tmp < 7800) || (tmp > 8700)) { //Get the first 9ms IE0 = 0; return; } tmp = ir_get_high_time(); //Get the low 4.5ms if((tmp < 3600) || (tmp > 4600)) { IE0 = 0; return; } for(i = 0; i < 4; i++){ for(j = 0;j < 8; j++) { tmp = ir_get_low_time(); //Get the 560us low voltage. if((tmp < 310) || (tmp > 720)) { IE0 = 0; return; } tmp = ir_get_high_time(); if ((tmp > 310) && (tmp < 720)) { //If the time between 1460us to 1900us. set 1 else set 0. recieved_byte >>= 1; } else if ((tmp > 1340)&&(tmp < 1750)) { recieved_byte >>= 1; recieved_byte |= 0x80; } else { //If not at that scope exist. IE0 = 0; return; } } ir_data[i] = recieved_byte; } ir_finish = 1; //Finish recieve. IE0 = 0; }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/SONG.h
<reponame>lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051- #ifndef _SONG_H #define _SONG_H #ifndef _SONG_C #endif code unsigned char FH[] = {0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8, 0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC, 0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFE, 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF}; code unsigned char FL[] = { 0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, 0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, 0x8F, 0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, 0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16}; code unsigned char song_code[] = {6, 2, 3, 5, 2, 1, 3, 2, 2, 5, 2, 2, 1, 3, 2, 6, 2, 1, 5, 2, 1,6, 2, 4, 3, 2, 2, 5, 2, 1, 6, 2, 1, 5, 2, 2, 3, 2, 2, 1, 2, 1,6, 1, 1, 5, 2, 1, 3, 2, 1, 2, 2, 4, 2, 2, 3, 3, 2, 1, 5, 2, 2, 5, 2, 1, 6, 2, 1, 3, 2, 2, 2, 2, 2, 1, 2, 4, 5, 2, 3, 3, 2, 1,2, 2, 1, 1, 2, 1, 6, 1, 1, 1, 2, 1, 5, 1, 6, 0, 0, 0}; unsigned char song_timer1_high = 0; //High eight bits for timer1. unsigned char song_timer1_low = 0; //Low eight bits for timer1. //Function defined at here. void song_begin(void); void song_delay(unsigned char t); #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/pins.h
<reponame>lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051- #ifndef _PINS_H #define _PINS_H #include <reg52.h> #include <intrins.h> #include <ctype.h> #include <stdio.h> //Define pins, used in this clock project. typedef signed char int8; typedef signed int int16; typedef signed long int32; typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uint32; //Define the DS1302 sbit DS_CK = P3^6; //The clock pin of DS1302 sbit DS_IO = P3^4; //The input/output pin of DS1302(data pin) sbit DS_CE = P3^5; //The selected pin of DS1302 //Define the LCD 1602 sbit LCD_RS=P2^6; //Select the data register(=1) or command register(=0) sbit LCD_E=P2^7; //Enable signal sbit LCD_RW=P2^5; //Read and write signal. sbit LCD_BUSY=P0^7; //Busy condition bit. #define LCD_DATA P0 //Define the data port of LCD1602. //Define the DS18B20 sbit DS18B20_IO = P3^7; //Define the data path of DS18B20. //Define the EEPROM 24C02. sbit SCL = P2^1; //Clock siganl of I2C. sbit SDA = P2^0; //Data signal of I2C. //Define the infrared IC. Using the NEC protocal. sbit IR_DATA = P3^2; //Define the loudspeaker. sbit BEEM = P1^5; #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/EEPROM.h
#ifndef _EEPROM_H #define _EEPROM_H #ifndef _EEPROM_C #endif //I2C and EEPROM Operate function. unsigned char eeprom_read_byte(unsigned char addr); void eeprom_write_byte(unsigned char addr, unsigned char dat); void eeprom_read_multi(unsigned char *buffer, unsigned char addr, unsigned char len); void eeprom_write_multi(unsigned char *buffer, unsigned char addr, unsigned char len); #endif
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/DS1302.c
<filename>code/DS1302.c #define _DS1302_C #include "pins.h" #include "DS1302.h" //Write one byte to DS1302. void ds1302_write_byte(unsigned char reg, unsigned char dat){ unsigned char i, addr; //Temp value. DS_CE = 0; _nop_(); DS_CK = 0; _nop_(); DS_CE = 1; //Select the DS1302 _nop_(); addr = reg<<1|0x80; //Change the registor number to the real address. for (i=0;i<8;i++) { //Send one byte address. DS_IO = addr&0x01; addr >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } for (i=0;i<8;i++) { //Send one byte data DS_IO = dat&0x01; dat >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } DS_CE = 0; //Release the DS1302. _nop_(); } //Read one byte from DS1302. unsigned char ds1302_read_byte(unsigned char reg){ unsigned char addr, i; unsigned char dat1, dat = 0; DS_CE = 0; _nop_(); DS_CK = 0; _nop_(); DS_CE = 1; //Select the DS1302 _nop_(); addr = reg<<1|0x81; //Change the registor number to the real address. for (i=0;i<8;i++) { //First send one byte address. DS_IO = addr&0x01; addr >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } //DS_IO = 1; //Release the data path. _nop_(); for(i=0;i<8;i++){ dat1 = DS_IO; dat = (dat>>1) | (dat1<<7); DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } DS_CE = 0; //Release the DS1302. _nop_(); DS_CK = 1; _nop_(); DS_IO = 0; _nop_(); DS_IO = 1; _nop_(); //DS_IO = 1; return dat; //Return the data. } //Burst write, since there are some special condition //the usual method may have mistake, this function write all data once for all. void ds1302_burst_write(unsigned char *dat) { unsigned char i, j = 0; unsigned com = 0xBE; unsigned tmp = 0; DS_CE = 0; _nop_(); DS_CK = 0; _nop_(); DS_CE = 1; //Select the DS1302. _nop_(); for (i=0;i<8;i++) { //Send one byte data, Write the burst write command. DS_IO = com&0x01; com >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } //DS_IO = 1; //Release the data path. for(j = 0;j<8;j++) { tmp = dat[j]; for (i=0;i<8;i++) { //Send one byte data DS_IO = tmp&0x01; tmp >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } _nop_(); //DS_IO = 1; //Release the data path. } //DS_CK = 0; //DS_CK = 1; DS_CE = 0; //Release the DS1302. _nop_(); } //Burst read, since there are some special condition //the usual method may have mistake, this function read data once for all. void ds1302_burst_read(unsigned char *dat) { unsigned char i,j, temp = 0; unsigned char com = 0xBF; DS_CE = 0; _nop_(); DS_CK = 0; _nop_(); DS_CE = 1; //Select the DS1302. _nop_(); for (i=0;i<8;i++) { //Send one byte data, Write the burst write command. DS_IO = com&0x01; com >>= 1; DS_CK = 1; _nop_(); DS_CK = 0; _nop_(); } //DS_IO = 1; //Release the data path. _nop_(); for(j=0;j<8;j++){ for(i=0x01;i!=0;i<<=1){ if(DS_IO != 0){ temp |= i; } DS_CK = 1; _nop_(); DS_CK = 0; } dat[j] = temp; temp = 0; _nop_(); } DS_CE = 0; //Release the DS1302. _nop_(); DS_CK = 1; _nop_(); DS_IO = 0; _nop_(); DS_IO = 1; _nop_(); } //Get the real time from DS1302. Return the result using tim pointer. void ds1302_get_time(struct time_and_date *tim) { unsigned char buffer[8]; ds1302_burst_read(buffer); tim->year = buffer[6] + 0x2000; tim->month = buffer[4]; tim->day = buffer[3]; tim->hour = buffer[2]; tim->minute = buffer[1]; tim->second = buffer[0]; tim->week = buffer[5]; //tim->year = ds1302_read_byte(6) + 0x2000; //tim->month = ds1302_read_byte(4); //tim->day = ds1302_read_byte(3); //tim->hour = ds1302_read_byte(2); //tim->minute = ds1302_read_byte(1); //tim->second = ds1302_read_byte(0); //tim->week = ds1302_read_byte(5); } //Set the real time to DS1302. void ds1302_set_time(struct time_and_date *tim) { unsigned char buffer[8]; buffer[0] = tim->second; buffer[1] = tim->minute; buffer[2] = tim->hour; buffer[3] = tim->day; buffer[4] = tim->month; buffer[5] = tim->week; buffer[6] = tim->year; buffer[7] = 0; ds1302_burst_write(buffer); } //DS1302 init function. Set the time at 2018,11,27, 12:00, week 2 void ds1302_init(void) { struct time_and_date code first_time[] = { 0x2018, 0x11, 0x27, 0x12, 0x00, 0x00, 0x02 }; DS_CE = 0; DS_CK = 0; if((ds1302_read_byte(0) & 0x80)) { ds1302_write_byte(7, 0x00); ds1302_set_time(&first_time); //ds1302_write_byte(7, 0x80); } } // void ds1302_date_to_str (struct time_and_date *Time) { Time->DateString[0] = ((Time->year>>4) & 0xF) + '0'; Time->DateString[1] = (Time->year & 0x0F) + '0'; Time->DateString[2] = '-'; Time->DateString[3] = (Time->month >> 4) + '0'; Time->DateString[4] = (Time->month & 0x0F) + '0'; Time->DateString[5] = '-'; Time->DateString[6] = (Time->day >> 4) + '0'; Time->DateString[7] = (Time->day & 0x0F) + '0'; Time->DateString[8] = '\0'; } // void ds1302_time_to_str(struct time_and_date *Time) { Time->TimeString[0] = (Time->hour >> 4) + '0'; Time->TimeString[1] =(Time->hour & 0x0F) + '0'; Time->TimeString[2] = ':'; Time->TimeString[3] = (Time->minute >> 4) + '0'; Time->TimeString[4] = (Time->minute & 0x0F) + '0'; Time->TimeString[5] = ':'; Time->TimeString[6] = (Time->second>> 4) + '0'; Time->TimeString[7] = (Time->second & 0x0F) + '0'; Time->TimeString[8] = '\0'; }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/EEPROM.c
#define _EEPROM_C #include "pins.h" #include "EEPROM.h" //The delay function. #define I2Cdelay() {_nop_();_nop_();_nop_();_nop_();} //Procedure to initialize I2C void startConfig(){ SDA = 1; SCL = 1; I2Cdelay(); SDA = 0; I2Cdelay(); SCL = 0; } //Procedure to stop I2C void stopConfig(){ SCL = 0; SDA = 0; I2Cdelay(); SCL = 1; I2Cdelay(); SDA = 1; I2Cdelay(); } bit writeI2C(unsigned char dat){ bit a; //return the acknolegement. unsigned char mask = 0x80; //mask = b1000,0000 while(mask !=0) { if ((mask&dat) == 0){ //Judge the present bit is 1 SDA = 0; } else { SDA = 1; } mask >>= 1; I2Cdelay(); SCL = 1; I2Cdelay(); //Transfer the data SCL = 0; } SDA = 1; I2Cdelay(); SCL = 1; a = SDA; I2Cdelay(); SCL = 0; return (~a); } //Read I2C from the bus unsigned char readI2C(){ unsigned char mask = 0x80; //masl value unsigned char d; //return data SDA = 1; //Make sure to release the bus. while(mask !=0) { I2Cdelay(); SCL = 1; if (SDA == 1){ //Judge the present bit is 1 d = d | mask; } else { d &= ~mask; } mask >>= 1; I2Cdelay(); SCL = 0; } SDA = 0; //Begin the ack I2Cdelay(); SCL = 1; I2Cdelay(); SCL = 0; //Finishing the ack. return d; } //Read the I2C without the ack unsigned char readI2CnoACK(){ unsigned char mask = 0x80; //masl value unsigned char d; //return data SDA = 1; //Make sure to release the bus. while(mask !=0) { I2Cdelay(); SCL = 1; if (SDA == 1){ //Judge the present bit is 1 d = d | mask; } else { d &= ~mask; } mask >>= 1; I2Cdelay(); SCL = 0; } SDA = 1; //SDA is high I2Cdelay(); SCL = 1; I2Cdelay(); SCL = 0; //So there is no ack. return d; } //Write one byte to EEPROM. Using I2C protocal. void eeprom_write_byte(unsigned char addr, unsigned char dat) { startConfig(); writeI2C(0xa0); writeI2C(addr); writeI2C(dat); stopConfig(); } //Read one byte from EEPROM. Using I2C protocal. unsigned char eeprom_read_byte(unsigned char addr) { unsigned char dat; startConfig(); writeI2C(0xa0); writeI2C(addr); startConfig(); writeI2C(0xa1); dat = readI2CnoACK(); stopConfig(); return dat; } //Read multi bytes from EEPROM. Using I2C protocal. void eeprom_read_multi(unsigned char *buffer, unsigned char addr, unsigned char len) { do { startConfig(); if (writeI2C(0xa0)) { break; } stopConfig(); } while(1); writeI2C(addr); startConfig(); writeI2C(0xa1); while(len > 1) { *buffer++ = readI2C(); len--; } *buffer = readI2CnoACK(); stopConfig(); } //Write multi bytes to EEPROM, Using the page write method, this method is quiker. Using I2C protocal. void eeprom_write_multi(unsigned char *buffer, unsigned char addr, unsigned char len) { while(len > 0) { do { startConfig(); if (writeI2C(0xa0)) { break; } stopConfig(); } while(1); writeI2C(addr); while(len > 0) { writeI2C(*buffer++); len--; addr++; if((addr&0x07) == 0) { break; } } stopConfig(); } }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/main.c
#include "pins.h" #include "LCD1602.h" #include "DS1302.h" #include "DS18B20.h" #include "EEPROM.h" struct time_and_date SetTime; //Infrared. //-------------------------------------------------------------------------------------- bit ir_finish = 0; //Ir flag if recieved data, set to 1, else set to 0. unsigned char ir_data[4]; //Data buffer since there are 4 bytes need to be recieved. const uint8 code ir_map[][2] = { //???????PC?????? {0x45,0x00}, {0x46,0x00}, {0x47,0x1B}, //??->? Mode->? ??->ESC {0x44,0x00}, {0x40,0x25}, {0x43,0x27}, //??->? ??->?? ??->?? {0x07,0x00}, {0x15,0x28}, {0x09,0x26}, // EQ->? ??->?? ??->?? {0x16, '0'}, {0x19,0x1B}, {0x0D,0x0D}, //'0'->'0' ??->ESC U/SD->?? {0x0C, '1'}, {0x18, '2'}, {0x5E, '3'}, //'1'->'1' '2'->'2' '3'->'3' {0x08, '4'}, {0x1C, '5'}, {0x5A, '6'}, //'4'->'4' '5'->'5' '6'->'6' {0x42, '7'}, {0x52, '8'}, {0x4A, '9'}, //'7'->'7' '6'->'8' '9'->'9' }; //--------------------------------------------------------------------------------------- //Song //--------------------------------------------------------------------------------------- code unsigned char FH[] = {0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8, 0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC, 0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFE, 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF}; code unsigned char FL[] = { 0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, 0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, 0x8F,0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, 0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16}; code unsigned char song_code[] = {6, 2, 3, 5, 2, 1, 3, 2, 2, 5, 2, 2, 1, 3, 2, 6, 2, 1, 5, 2, 1,6, 2, 4, 3, 2, 2, 5, 2, 1, 6, 2, 1, 5, 2, 2, 3, 2, 2, 1, 2, 1,6, 1, 1, 5, 2, 1, 3, 2, 1, 2, 2, 4, 2, 2, 3, 3, 2, 1, 5, 2, 2, 5, 2, 1, 6, 2, 1, 3, 2, 2, 2, 2, 2, 1, 2, 4, 5, 2, 3, 3, 2, 1,2, 2, 1, 1, 2, 1, 6, 1, 1, 1, 2, 1, 5, 1, 6, 0, 0, 0}; unsigned char song_timer1_high = 0; //High eight bits for timer1. unsigned char song_timer1_low = 0; //Low eight bits for timer1. unsigned char song_time = 1; //Function defined at here. void song_begin(void); void song_delay(unsigned char t); //--------------------------------------------------------------------------------------- void delayms(unsigned int itime); void show_time(struct time_and_date *tim); void show_temp(); void eeprom_store_time(struct time_and_date *tim); void ir_key_serve(void); void ir_init(void); void delay200ms(void) { unsigned char i,j,k; for(i=201;i>0;i--) for(j=32;j>0;j--) for(k=14;k>0;k--); } unsigned char psec; void main(void) { //unsigned char buf[6]; unsigned char i = 0; IT0=1; EX0=1; EA=1; IR_DATA=1; lcd_init(); ds1302_init(); ds18b20_start_transition(); ds1302_get_time(&SetTime); eeprom_store_time(&SetTime); delayms(30); RCAP2H=0x02; RCAP2L=0x18; ET2=1; EA=1; TR2=1; ir_init(); while(1){ song_begin(); } } void delayms(unsigned int itime){ unsigned int i,j; for (i = 0;i<itime; i++) for (j = 0;j<1275;j++); } void show_time(struct time_and_date *tim) { unsigned char str[18]; str[0] = ((tim->year>>4) & 0xF) + '0'; str[1] = (tim->year & 0x0F) + '0'; str[2] = '-'; str[3] = (tim->month >> 4) + '0'; str[4] = (tim->month & 0x0F) + '0'; str[5] = (tim->day >> 4) + '0'; str[6] = (tim->day & 0x0F) + '0'; str[7] = ' '; str[8] = (tim->hour >> 4) + '0'; str[9] = (tim->hour & 0x0F) + '0'; str[10] = ':'; str[11] = (tim->minute >> 4) + '0'; str[12] = (tim->minute & 0x0F) + '0'; str[13] = ':'; str[14] = (tim->second>> 4) + '0'; str[15] = (tim->second & 0x0F) + '0'; str[16] = '\0'; lcd_show_string(0, 0, "Temp:"); lcd_show_string(0, 1, str); } void show_temp() { int temper = 0; unsigned char str[5]; unsigned char a,b; a = ds18b20_get_temp(&temper); b = ds18b20_start_transition(); temper >>= 4; str[0] = (temper/10) + '0'; str[1] = (temper%10) + '0'; str[2] = '\''; str[3] = 'C'; str[4] = '\0'; lcd_show_string(0,0,"Temp:"); lcd_show_string(8,0,str); } void Timer0Interrupt(void) interrupt 1 { //TH0 = 0x10; //TL0 = 0x00; //ds1302_get_time(&SetTime); //if(psec != SetTime.second){ //show_time(); //add your code here! } void eeprom_store_time(struct time_and_date *tim) { unsigned char buffer[6]; buffer[0] = 0x2018; buffer[1] = 0x11; buffer[2] = 0x27; buffer[3] = 0x12; buffer[4] = 0x00; buffer[5] = tim->second; eeprom_write_multi(buffer, 0x30, 6); } void Timer2_Server(void) interrupt 5 { static unsigned char Timer2_Server_Count; RCAP2H=0x02; RCAP2L=0x18; Timer2_Server_Count++; if(Timer2_Server_Count==10) { Timer2_Server_Count=0; TF2=0; ds1302_get_time(&SetTime); ds1302_date_to_str (&SetTime); ds1302_time_to_str(&SetTime); lcd_show_string(0, 1, SetTime.DateString); lcd_show_string(8, 1, SetTime.TimeString); ir_key_serve(); show_temp(); //lcd_show_string(14,0,"md"); } } //---------------------------------------------------------------------------------------------------------------------------------------- void ir_delay(unsigned int i) { while(i--); } void ir_key_serve(void){ unsigned char i = 0; if(ir_finish){ ir_finish = 0; for (i = 0; i < 21; i++) { if(ir_data[2] == ir_map[i][0]) { lcd_set_cursor(13,0); lcd_write_data(ir_map[i][1]); //lcd_show_string(0,13, ir_map[i][1]); break; } } } } //Init the infrared equipment. void ir_init(void) { IR_DATA = 1; //To prepare read the value. TMOD = 0x11; TH0 = 0x00; TL0 = 0x00; EA = 1; //Open the global interrupt ET0 = 0; //Forbid the timer0 interrupt TR0 = 0; //Shut down the timer0. IT0 = 1; //Open the external interrupt0 EX0 = 1; //Using the edge triger. } //Get the low voltage time. unsigned int ir_get_high_time(){ TH0 = 0; TL0 = 0; TR0 = 1; //Open the timer 0 while(IR_DATA) { //Get the low time if (TH0 > 0X40) //To prevent the wrong condition break if takes too long. break; } TR0 = 0; //Shut down the timer0. return (TH0*256 + TL0); } //Get the high voltage time. unsigned int ir_get_low_time() { TH0 = 0; TL0 = 0; TR0 = 1; while(!IR_DATA){ if (TH0 > 0x40) break; } TR0 = 0; return (TH0*256 + TL0); } //Interrupt0 serve function. Get the data. void ir_get_data() interrupt 0 { unsigned char i, j = 0; unsigned char recieved_byte; unsigned int tmp; tmp = ir_get_low_time(); if((tmp < 7000) || (tmp > 10000)) { //Get the first 9ms IE0 = 0; return; } tmp = ir_get_high_time(); //Get the low 4.5ms if((tmp < 3500) || (tmp > 5000)) { IE0 = 0; return; } for(i = 0; i < 4; i++){ for(j = 0;j < 8; j++) { tmp = ir_get_low_time(); //Get the 560us low voltage. if((tmp < 310) || (tmp > 720)) { IE0 = 0; return; } tmp = ir_get_high_time(); if ((tmp > 310) && (tmp < 720)) { //If the time between 1460us to 1900us. set 1 else set 0. recieved_byte >>= 1; } else if ((tmp > 1300)&&(tmp < 1800)) { recieved_byte >>= 1; recieved_byte |= 0x80; } else { //If not at that scope exist. IE0 = 0; return; } } ir_data[i] = recieved_byte; } ir_finish = 1; //Finish recieve. IE0 = 0; } //--------------------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------------------------- void song_delay(unsigned char t) { unsigned char i; unsigned long j; for(i=0;i<t;i++) for(j=0;j<8000;j++); TR1 = 0; } void song_begin(void){ unsigned char i,m = 0; i = 0; m = 0; song_time = 1; TMOD = 0x11; ET1 = 1; EA = 1; //BEEM = 0; while(song_time) { m = song_code[i] + 7*song_code[i+1] - 1; song_timer1_high = FH[m]; song_timer1_low = FL[m]; song_time = song_code[i+2]; i+=3; TH1 = song_timer1_high; TL1 = song_timer1_low; TR1 = 1; song_delay(song_time); } } //--------------------------------------------------------------------------------------------------------------------------------------------------- void Timer1Interrupt(void) interrupt 3 //Timer1's interrupt. { TR1 = 0; BEEM = !BEEM; TH1 = song_timer1_high; TL1 = song_timer1_low; TR1 = 1; }
lirui-shanghaitech/A-multi-functions-digital-clock-based-on-8051-
code/DS18B20.h
#ifndef _DS18B20_H #define _DS18B20_H #ifndef _DS18B20_C #endif //Function define.(API) bit ds18b20_get_temp(int *temperature); bit ds18b20_start_transition(); void ds18b20_write_byte(unsigned char dat); unsigned char ds18b20_read_byte(); #endif
BryceStandley/TNAH
core/src/TNAH/Physics/PhysicsEvents.h
<gh_stars>1-10 #pragma once #pragma warning(push, 0) #include <reactphysics3d/reactphysics3d.h> #include <entt/entt.hpp> #pragma warning(pop) namespace tnah { namespace Physics { /** * @class PhysicsEvents * * @brief The physics event class that inherits from the react physics 3d eventListener class * * @author <NAME> * @date 11/09/2021 */ class PhysicsEvents : public rp3d::EventListener { public: /** * @fn void PhysicsEvents::onContact(const CallbackData& callbackData) override; * * @brief Event callback overriding React. Naming must be the same as React. * * @author <NAME> * @date 11/09/2021 * * @param callbackData Information describing the callback. */ void onContact(const CallbackData& callbackData) override; /** * @fn void PhysicsEvents::onTrigger(const rp3d::OverlapCallback::CallbackData& callbackData) override; * * @brief Event callback overriding React. Naming must be the same as React. * * @author <NAME> * @date 11/09/2021 * * @param callbackData Information describing the callback. */ void onTrigger(const rp3d::OverlapCallback::CallbackData& callbackData) override; }; } }
BryceStandley/TNAH
core/src/TNAH/Physics/PhysicsEngine.h
#pragma once #pragma warning(push, 0) #include <reactphysics3d/reactphysics3d.h> #pragma warning(pop) #include <entt/entt.hpp> #include "CollisionDetectionEngine.h" #include "PhysicsStructures.h" #include "Rigidbody.h" #include "TNAH/Physics/PhysicsTimestep.h" #include "TNAH/Scene/Components/Components.h" #include "TNAH/Scene/Components/PhysicsComponents.h" #include "Rigidbody.h" #include "TNAH/Core/Timestep.h" #include "TNAH/Scene/Components/PhysicsComponents.h" namespace tnah { class Scene; class Renderer; class GameObject; } /** * @namespace tnah::Physics {} * * @brief Main Physics Sub-namespace * */ namespace tnah::Physics { #pragma region PhysicsManager /** * @class PhysicsManager * * @brief Manager for physics that inherits from the RefCounted class. This class is to remain private and contain * all ReactPhysics3D world objects. Any control of the PhysicsManager should be done from tnah::PhysicsEngine::PhysicsEngine * * @author <NAME> * @date 11/09/2021 */ class PhysicsManager : public RefCounted { public: /** * @fn PhysicsManager::PhysicsManager(); * * @brief Default constructor. * This constructor is empty as the object requires the PhysicsEngine::Initialise(rp3d::EventListener* collisionEventListener) to be called * * @author <NAME> * @date 12/09/2021 */ PhysicsManager(); /** * @fn PhysicsManager::~PhysicsManager(); * * @brief Destructor. Safeguards prevent deletion of empty pointers of * PhysicsManager::m_PhysicsWorld and PhysicsManager::m_PhysicsLogger if PhysicsEngine::Initialise(rp3d::EventListener* collisionEventListener) * was never called or PhysicsEngine::Initialise(rp3d::EventListener* collisionEventListener) was called and PhysicsEngine::PhysicsLoggerInit() was not. * * @author <NAME> * @date 12/09/2021 */ ~PhysicsManager(); /** * @brief Get the Gravity object * @author <NAME> * @date 06-11-2021 * @return glm::vec3& */ glm::vec3& GetGravity() { return m_Gravity; } /** * @brief Set the Gravity object * @author <NAME> * @date 06-11-2021 */ void SetGravity(const glm::vec3& gravity) { m_Gravity = gravity; } /** * @brief Set the Gravity State object * @author <NAME> * @date 06-11-2021 */ void SetGravityState(const bool& state) { m_GravityEnabled = state; } /** * @brief Get the Gravity State object * @author <NAME> * @date 06-11-2021 * @return true * @return false */ bool& GetGravityState() { return m_GravityEnabled; } /** * @brief Get the Sleep State object * @author <NAME> * @date 06-11-2021 * @return true * @return false */ bool& GetSleepState() { return m_SleepAllowed; } /** * @brief Get the Collision Detection Engine object * @author <NAME> * @date 06-11-2021 * @return Ref<CollisionDetectionEngine>& */ Ref<CollisionDetectionEngine>& GetCollisionDetectionEngine() { return m_CollisionDetectionEngine; } private: /** * @fn bool PhysicsManager::Initialise(rp3d::EventListener * collisionEventListener); * * @brief Initialises this object * * @author <NAME> * @date 12/09/2021 * * @param [in,out] collisionEventListener If non-null, the collision event listener. * * @returns True if it succeeds, false if it fails. */ bool Initialise(rp3d::EventListener * collisionEventListener); /** * @fn void PhysicsManager::OnFixedUpdate(PhysicsTimestep timestep); * * @brief Executes the 'fixed update' action * * @author <NAME> * @date 12/09/2021 * * @param timestep The timestep. */ void OnFixedUpdate(Timestep deltaTime, PhysicsTimestep timestep) const; /** * @fn void PhysicsManager::Destroy(); * * @brief Destroys this object * * @author <NAME> * @date 12/09/2021 */ void Destroy(); /** * @fn rp3d::RigidBody* PhysicsManager::CreateRigidBody(const TransformComponent& transform); * * @brief Creates rigid body * * @author <NAME> * @date 12/09/2021 * * @param transform A transform component. * * @returns Null if it fails, else the new rigid body. */ rp3d::RigidBody* CreateRigidBody(const TransformComponent& transform) const; /** * @fn void PhysicsManager::DestroyRigidBody(rp3d::RigidBody* rigidBody); * * @brief Destroys the rigid body described by rigidBody * * @author <NAME> * @date 12/09/2021 * * @param [in,out] rigidBody If non-null, the rigid body. */ void DestroyRigidBody(rp3d::CollisionBody* rigidBody) const; /** * @fn rp3d::CollisionBody* PhysicsManager::CreateCollisionBody(const TransformComponent& transform); * * @brief Creates collision body * * @author <NAME> * @date 12/09/2021 * * @param transform The transform. * * @returns Null if it fails, else the new collision body. */ rp3d::CollisionBody* CreateCollisionBody(const TransformComponent& transform) const; /** * @fn void PhysicsManager::DestroyCollisionBody(rp3d::CollisionBody * body); * * @brief Destroys the collision body described by body * * @author <NAME> * @date 12/09/2021 * * @param [in,out] body If non-null, the body. */ void DestroyCollisionBody(rp3d::CollisionBody * body) const; /** * @fn void PhysicsManager::CreateColliderRenderer(); * * @brief Creates collider renderer * * @author <NAME> * @date 12/09/2021 */ void CreateColliderRenderer(); private: /** @brief The physics common */ rp3d::PhysicsCommon m_PhysicsCommon; /** @brief Pointer to The physics world */ rp3d::PhysicsWorld* m_PhysicsWorld = nullptr; /** @brief Pointer to physics logger */ //rp3d::DefaultLogger* m_PhysicsLogger = nullptr; /** @brief True to collider render */ bool m_ColliderRender = false; /** @brief True if the collider renderer has been initialized */ bool m_ColliderRendererInit = false; Ref<VertexArray> m_LinesVertexArray; /** @brief Pointer to the buffer for lines vertex data */ Ref<VertexBuffer> m_LinesVertexBuffer; /** @brief Pointer to array for triangle vertex data */ Ref<VertexArray> m_TriangleVertexArray; /** @brief Pointer to Buffer for triangle vertex data */ Ref<VertexBuffer> m_TriangleVertexBuffer; /** @brief Shader used for the collider renderer */ Ref<Shader> m_Shader; /** @brief Layout of the collider renderer vertex buffers */ VertexBufferLayout m_ColliderLayout; /** * @brief If gravity is enabled or not * @author <NAME> * @date 06-11-2021 */ bool m_GravityEnabled = true; /** * @brief The value of gravity in the world * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_Gravity = {0.0f, -9.8f, 0.0f}; /** @brief True to active */ bool m_Active = false; /** @brief Used to tell the physics system if the logging should be enabled*/ bool m_Logging = false; /** * @brief All RigidBody objects in the world * @author <NAME> * @date 06-11-2021 */ std::unordered_map<uint32_t, Ref<RigidBody>> m_Rigidbodies; /** * @brief Total Rigidbody objects in the world * @author <NAME> * @date 06-11-2021 */ uint32_t m_TotalRigidbodies = 0; /** * @brief All Collider objects in the world * @author <NAME> * @date 06-11-2021 */ std::unordered_map<uint32_t, Ref<Collider>> m_Colliders; /** * @brief Total Collider objects in the world * @author <NAME> * @date 06-11-2021 */ uint32_t m_TotalColliders = 0; /** @brief a static reference to the active Collision Detection Engine */ static Ref<CollisionDetectionEngine> m_CollisionDetectionEngine; /** * @brief Are RigidBody objects allowed to sleep? * @author <NAME> * @date 06-11-2021 */ bool m_SleepAllowed = false; friend class PhysicsEngine; }; #pragma endregion PhysicsManager #pragma region PhysicsEngine /** * @class PhysicsEngine * * @brief A physics class responsible for the engine physics. All actual physics calculations are processed within * this class. * * @author <NAME> * @date 12/09/2021 */ class PhysicsEngine { public: /** * @fn static Ref<PhysicsManager> PhysicsEngine::GetManager(); * * @brief Gets a pointer to the PhysicsManager * * @author <NAME> * @date 12/09/2021 * * @returns The manager. */ static Ref<PhysicsManager> GetManager(); /** * @fn static bool PhysicsEngine::IsActive(); * * @brief Query if the physics is active * * @author <NAME> * @date 12/09/2021 * * @returns True if active, false if not. */ static bool IsActive(); /** * @fn static bool PhysicsEngine::Initialise(rp3d::EventListener * collisionEventListener); * * @brief Initialises the physics and its logger * * @author <NAME> * @date 12/09/2021 * * @param [in,out] collisionEventListener If non-null, the collision event listener. * * @returns True if it succeeds, false if it fails. */ static bool Initialise(rp3d::EventListener * collisionEventListener); /** * @fn static void PhysicsEngine::OnFixedUpdate(PhysicsTimestep timestep); * * @brief Executes the 'fixed update' action * * @author <NAME> * @date 12/09/2021 * * @param timestep The timestep. */ static void OnFixedUpdate(Timestep deltaTime, PhysicsTimestep timestep, entt::registry& componentRegistry); /** * @fn static void PhysicsEngine::OnUpdate(Timestep timestep); * * @brief Physics update for any disconnected objects not tied directly to the fixed physics updates. * * @author <NAME> * @date 10/10/2021 * * @param timestep The timestep. */ static void OnUpdate(Timestep timestep); /** * @fn static void PhysicsEngine::Destroy(); * * @brief Destroys this object * * @author <NAME> * @date 12/09/2021 */ static void Destroy(); /** * @fn static void PhysicsEngine::DestroyRigidbody(rp3d::RigidBody* body); * * @brief Destroys the rigidbody described by body * * @author <NAME> * @date 12/09/2021 * * @param [in,out] body If non-null, the body. */ static void DestroyRigidbody(Ref<RigidBody> rigidbody); /** * @fn static rp3d::RigidBody* PhysicsEngine::CreateRigidbody(const TransformComponent& transform); * * @brief Creates a rigidbody * * @author <NAME> * @date 12/09/2021 * * @param transform The transform. * * @returns Null if it fails, else the new rigidbody. */ static Ref<RigidBody> CreateRigidbody(GameObject& gameObject); /** * @fn static void PhysicsEngine::ToggleColliderRendering(); * * @brief Toggle collider rendering * * @author <NAME> * @date 12/09/2021 */ static void ToggleColliderRendering(); /** * @fn static void PhysicsEngine::GetColliderRendererHandle(); * * @brief Gets the Collider renderer handle * * @author <NAME> * @date 12/09/2021 */ static bool& GetColliderRendererHandle(); /** * @fn static TransformComponent PhysicsEngine::GetColliderRendererTransform(); * * @brief Gets the transform of the renderer * * @author <NAME> * @date 12/09/2021 */ static TransformComponent GetColliderRendererTransform(); /** * @fn static Ref<Collider> CreateBoxCollider(Ref<RigidBody> rigidbody, const glm::vec3& halfExtents); * * @brief Creates box shape * * @author <NAME> * @date 12/09/2021 * * @param rigidbody * @param halfExtents Extents of the half. * * @returns Null if it fails, else the new box shape. */ static Ref<Collider> CreateBoxCollider(Ref<RigidBody> rigidbody, const glm::vec3& halfExtents); /** * @fn static Ref<Collider> CreateSphereCollider(Ref<RigidBody> rigidbody, const float& radius); * * @brief Creates sphere shape * * @author <NAME> * @date 12/09/2021 * * @param rigidbody * @param radius The radius. * * @returns Null if it fails, else the new sphere shape. */ static Ref<Collider> CreateSphereCollider(Ref<RigidBody> rigidbody, const float& radius); /** * @fn static Ref<Collider> CreateCapsuleCollider(Ref<RigidBody> rigidbody, const float& radius, const float& height); * * @brief Creates capsule shape * * @author <NAME> * @date 12/09/2021 * * @param rigidbody * @param radius The radius. * @param height The height. * * @returns Null if it fails, else the new capsule shape. */ static Ref<Collider> CreateCapsuleCollider(Ref<RigidBody> rigidbody, const float& radius, const float& height); private: /** * @fn void PhysicsEngine::EnableLogging(); * * @brief Enables logging for the physics system * * @author <NAME> * @date 12/09/2021 * */ static void EnableLogging(); /** * @fn static bool IsColliderRenderingEnabled(); * * @brief Checks if collider rendering is enabled * * @author <NAME> * @date 12/09/2021 * * @return bool If the renderer is enabled * */ static bool IsColliderRenderingEnabled(); /** * @fn static std::pair<std::pair<Ref<VertexArray>, Ref<VertexBuffer>>, std::pair<Ref<VertexArray>, Ref<VertexBuffer>>> PhysicsEngine::GetColliderRenderObjects(); * * @brief Gets collider render objects by using a pair to retreive the VAO and VBO data for lines and triangles * * @author <NAME> * @date 12/09/2021 * * @returns The collider render objects. */ static std::pair<std::pair<Ref<VertexArray>, Ref<VertexBuffer>>, std::pair<Ref<VertexArray>, Ref<VertexBuffer>>> GetColliderRenderObjects(); /** * @fn static Ref<Shader> PhysicsEngine::GetColliderShader(); * * @brief Gets collider shader * * @author <NAME> * @date 12/09/2021 * * @returns The collider shader. */ static Ref<Shader> GetColliderShader(); /** * @fn static void PhysicsEngine::UpdateColliderRenderer(); * * @brief Updates the collider renderer * * @author <NAME> * @date 12/09/2021 */ static void UpdateColliderRenderer(); /** * @fn static rp3d::DebugRenderer* PhysicsEngine::GetColliderRenderer(); * * @brief Gets collider renderer * * @author <NAME> * @date 12/09/2021 * * @returns The collider renderer. */ static rp3d::DebugRenderer* GetColliderRenderer(); /** * @fn static void PhysicsEngine::PhysicsLoggerInit(); * * @brief Initialise the physics logger * * @author <NAME> * @date 12/09/2021 */ static void PhysicsLoggerInit(); /** * @brief Processes collisions in the CollisionDetectionEngine collision queue * @author <NAME> * @date 06-11-2021 */ static void ProcessCollisions(); /** * @brief Processes velocities for all RigidBody objects in the world * @author <NAME> * @date 06-11-2021 */ static void ProcessRigidbodyVelocities(const Timestep& deltaTime, entt::registry& componentRegistry); /** * @brief Processes position and orientations for all RigidBody objects in the world * @author <NAME> * @date 06-11-2021 */ static void ProcessRigidbodyPositions(const Timestep& deltaTime, entt::registry& componentRegistry); /** * @brief Resets external force and torque applied to Rigidbody objects in the world * @author <NAME> * @date 06-11-2021 */ static void ResetRigidbodyForcesAndTorques(entt::registry& componentRegistry); /** * @brief Updates the inertia tensor of each RigidBody object in the world * @author <NAME> * @date 06-11-2021 */ static void UpdateInertiaTensor(entt::registry& componentRegistry); /** * @brief Updates all state and transform values for React on each RigidBody in the world * @author <NAME> * @date 06-11-2021 */ static void UpdateBodies(entt::registry& componentRegistry); /** * @brief Updates and checks each RigidBody object in the world if it can be put to sleep * @author <NAME> * @date 06-11-2021 */ static void UpdateSleepState(entt::registry& componentRegistry, Timestep deltaTime); private: /** @brief a static reference to the active physics manager */ static Ref<PhysicsManager> m_PhysicsManager; /** @brief Transform used for rendering the colliders within the scene*/ static TransformComponent m_ColliderTransform; friend class tnah::Scene; friend class tnah::Renderer; }; #pragma endregion PhysicsEngine }
BryceStandley/TNAH
core/src/TNAH/Physics/Collider.h
#pragma once #include "PhysicsStructures.h" #include "TNAH/Core/Math.h" #pragma warning(push, 0) #include <reactphysics3d/reactphysics3d.h> #pragma warning(pop) namespace tnah::Physics { /** * @class Collider * @brief Class to contain the required information about Colliders * @author <NAME> * @date 06-11-2021 */ class Collider : public RefCounted { public: /** * @enum Type * * @brief Different type flag enum. * * @author <NAME> * @date 6/11/2021 * */ enum class Type { Box, Sphere, Capsule }; /** * @fn tnah::Physics::Collider::Collider(); * * @brief Constructor * * @author <NAME> * @date 6/11/2021 * */ Collider(); /** Collider(rp3d::CollisionShape* collider, Type type); * * @brief Constructor * * @author <NAME> * @date 6/11/2021 * * @param collider * @param type * @return * **/ Collider(rp3d::CollisionShape* collider, Type type); /** * @fn tnah::Ref<tnah::Physics::Collider> Create(rp3d::CollisionShape* collider); * * @brief Constructor of Ref * * @author <NAME> * @date 6/11/2021 * * @param collider * @return collider Ref * */ static Ref<Collider> Create(rp3d::CollisionShape* collider, Type type); /** * @fn void Collider::SetPosition(const glm::vec3& position); * * @brief Sets the position value * * @author <NAME> * @date 6/11/2021 * * @param position * @return void * */ void SetPosition(const glm::vec3& position) { m_LocalPosition = position; } /** * @fn void SetOrientation(const glm::quat& orientation); * * @brief Sets the orientation value * * @author <NAME> * @date 6/11/2021 * * @param orientation * @return void * */ void SetOrientation(const glm::quat& orientation) { m_LocalOrientation = orientation; } /** * @fn glm::vec3 GetColliderPosition() const * * * @brief Get the Collider Position object * * @author <NAME> * * @return glm::vec3 */ glm::vec3 GetColliderPosition() const { return m_LocalPosition; } /** * @fn glm::quat GetColliderOrientation() const * * * @brief Get the Collider Orientation object * * @author <NAME> * * @return glm::quat */ glm::quat GetColliderOrientation() const { return m_LocalOrientation; } /** * @fn BodyMass& GetColliderMass() * * * @brief Get the Collider Mass object * * @author <NAME> * * @return BodyMass& */ BodyMass& GetColliderMass() { return m_Mass; } /** * @brief Get the Type object * @author <NAME> * @date 06-11-2021 * @return Type */ Type GetType() const { return m_Type; } /** * @brief Get the Collision Shape Pair object * @author <NAME> * @date 06-11-2021 * @return std::pair<Type, rp3d::CollisionShape*> */ std::pair<Type, rp3d::CollisionShape*> GetCollisionShapePair() { return { m_Type, m_Collider }; } /** * @brief Get the Local Collider Inertia Tensor object * @author <NAME> * @date 06-11-2021 * @return glm::vec3 */ glm::vec3 GetLocalColliderInertiaTensor(); /** * @brief Get the Volume object * @author <NAME> * @date 06-11-2021 * @return float */ float GetVolume() { return m_Volume; } /** * @brief Set the Volume object * @author <NAME> * @date 06-11-2021 */ void SetVolume(const float value) { m_Volume = value; } /** * @brief Get the Density object * @author <NAME> * @date 06-11-2021 * @return float */ float GetDensity() { return m_Density; } /** * @brief Set the Density object * @author <NAME> * @date 06-11-2021 */ void SetDensity(const float value) { m_Density = value; } private: /** * @fn void InitializeBox(); * * @brief Sets us the local mass values of the Collider based on the BoxShape. * @author <NAME> */ void InitializeBox(); /** * @fn void InitializeSphere(); * * @brief Sets us the local mass values of the Collider based on the SphereShape. * @author <NAME> */ void InitializeSphere(); /** * @fn void InitializeCapsule(); * * @brief Sets us the local mass values of the Collider based on the CapsuleShape. * @author <NAME> */ void InitializeCapsule(); private: /** * @var m_Collider * * @brief The Reactphysics3D CollisionShape. This needs to be reinterpreted into a BoxShape or SphereShape depending on the ColliderType. */ rp3d::CollisionShape* m_Collider = nullptr; /** * @var m_Type * * @brief The type of the Collider. Either Box or Sphere currently. */ Type m_Type = Type::Box; /** * @var m_LocalPosition * * @brief The position of the Collider locally to its parent Rigidbody. * @note The position should always be at 0,0,0 ie the centre of the Rigidbody. * @note However the position should be changed if the object requires multiple colliders with different positions relative to the Rigidbody. */ glm::vec3 m_LocalPosition = {}; /** * @var m_LocalOrientation * * @brief The orientation of the Collider locally to its parent Rigidbody. */ glm::quat m_LocalOrientation = {}; /** * @var m_Mass * * @brief The local BodyMass information for this Collider. */ BodyMass m_Mass; /** * @var m_InertiaTensor * * @brief The Inertia tensor of the collider */ InertiaTensor m_InertiaTensor; /** * @var m_ID * @brief Id of the collider * @author <NAME> * @date 06-11-2021 */ uint32_t m_ID = 0; /** * @var m_Volume * * @brief The volume of the collider in meters cubed. */ float m_Volume = 0.0f; /** * @var m_Density * * @brief The density of the colliders material in kg per meter cubed. Default 1000kg/m3 ie the density of water. */ float m_Density = 1.0f; friend class PhysicsEngine; friend class EditorUI; friend class Serializer; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/SceneCamera.h
#pragma once #include "TNAH/Renderer/Camera.h" namespace tnah { class TransformComponent; class SceneCamera : public Camera { public: enum class ProjectionType { Perspective = 0, Orthographic = 1 }; public: /** * * \fn void SetPerspective * * \brief Sets the perspective of the camera * * \author <NAME> * \date 13/9/2021 * * \param verticalFOV * \param nearClip * \param farClip * * */ void SetPerspective(float verticalFOV, float nearClip = 0.01f, float farClip = 1000.0f); /** * * \fn void SetOrthographic * * \brief Sets the orthographic settings of the camea * * \author <NAME> * \date 13/9/2021 * * \param size * \param nearClip * \param farClip * * */ void SetOrthographic(float size, float nearClip = -1.0f, float farClip = 1.0f); /** * * \fn void SetViewportSize * * \brief Sets the viewport size * * \author <NAME> * \date 13/9/2021 * * \param width * \param height * * */ void SetViewportSize(uint32_t width, uint32_t height); /** * * \fn glm::vec2 GetViewportSize * * \brief Gets the viewport size * * \author <NAME> * \date 13/9/2021 * * * \return * */ glm::vec2 GetViewportSize() const {return glm::vec2(m_ViewportWidth, m_ViewportHeight);} /** * * \fn void SetPerspectiveVerticalFOV * * \brief Sets the perspective field of view * * \author <NAME> * \date 13/9/2021 * * \param verticalFov * * */ void SetPerspectiveVerticalFOV(float verticalFov) { m_PerspectiveFOV = glm::radians(verticalFov); } /** * * \fn float GetPerspectiveVerticalFOV * * \brief Gets the perspective field of view * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetPerspectiveVerticalFOV() const { return glm::degrees(m_PerspectiveFOV); } /** * * \fn void SetPerspectiveNearClip * * \brief Sets the perspective near clip plane * * \author <NAME> * \date 13/9/2021 * * \param nearClip * * */ void SetPerspectiveNearClip(float nearClip) { m_PerspectiveNear = nearClip; } /** * * \fn float GetPerspectiveNearClip * * \brief Gets the perspective near clip plane * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetPerspectiveNearClip() const { return m_PerspectiveNear; } /** * * \fn void SetPerspectiveFarClip * * \brief Sets the perspective far clip plane * * \author <NAME> * \date 13/9/2021 * * \param farClip * * */ void SetPerspectiveFarClip(float farClip) { m_PerspectiveFar = farClip; } /** * * \fn float GetPerspectiveFarClip * * \brief Gets the perspective far clip plane * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetPerspectiveFarClip() const { return m_PerspectiveFar; } /** * * \fn void SetOrthographicSize * * \brief Sets the orthographic size * * \author <NAME> * \date 13/9/2021 * * \param size * * */ void SetOrthographicSize(float size) { m_OrthographicSize = size; } /** * * \fn float GetOrthographicSize * * \brief Gets the orthographic size * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetOrthographicSize() const { return m_OrthographicSize; } /** * * \fn void SetOrthographicNearClip * * \brief Sets the othographic near clip plane * * \author <NAME> * \date 13/9/2021 * * \param nearClip * * */ void SetOrthographicNearClip(float nearClip) { m_OrthographicNear = nearClip; } /** * * \fn float GetOrthographicNearClip * * \brief Sets the othographic near clip plane * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetOrthographicNearClip() const { return m_OrthographicNear; } /** * * \fn void SetOrthographicFarClip * * \brief Sets the othograohic far clip plane * * \author <NAME> * \date 13/9/2021 * * \param farClip * * */ void SetOrthographicFarClip(float farClip) { m_OrthographicFar = farClip; } /** * * \fn float GetOrthographicFarClip * * \brief Gets the othographic far clip plane * * \author <NAME> * \date 13/9/2021 * * * \return * */ float GetOrthographicFarClip() const { return m_OrthographicFar; } /** * * \fn void SetProjectionType * * \brief Sets the projection type of the camera * * \author <NAME> * \date 13/9/2021 * * \param type * * */ void SetProjectionType(ProjectionType type) { m_ProjectionType = type; } /** * * \fn ProjectionType GetProjectionType * * \brief Gets the projection type of the camera * * \author <NAME> * \date 13/9/2021 * * * \return * */ ProjectionType GetProjectionType() const { return m_ProjectionType; } /** * * \fn const glm::mat4 & GetViewMatrix * * \brief Gets the view matrix of the camera * * \author <NAME> * \date 13/9/2021 * * * \return * */ const glm::mat4& GetViewMatrix() const { return m_ViewMatrix; } /** * * \fn const glm::mat4 & GetInvertedTransformViewMatrix * * \brief Gets the view matrix from the camera derived from its inverted transform component * * \author <NAME> * \date 13/9/2021 * * * \return * */ const glm::mat4& GetInvertedTransformViewMatrix() const { return m_InvertTransformViewMatrix; } /** * * \fn void OnUpdate * * \brief Updates the camera * * \author <NAME> * \date 13/9/2021 * * \param transform * * */ void OnUpdate(TransformComponent& transform); /** * * \fn void OnCameraChange * * \brief Updates view and projection matrix values when the camera moves or changes * * \author <NAME> * \date 13/9/2021 * * \param transform * * */ void OnCameraChange(TransformComponent& transform); /** * * \fn glm::quat GetOrientation * * \brief Gets the orientation of the camera * * \author <NAME> * \date 13/9/2021 * * \param transform * * \return * */ glm::quat GetOrientation(TransformComponent& transform); private: /** @brief The projection type of the camera */ ProjectionType m_ProjectionType = ProjectionType::Perspective; /** @brief The width type of the cameras viewport */ uint32_t m_ViewportWidth = 1280; /** @brief The height type of the cameras viewport */ uint32_t m_ViewportHeight = 720; /** @brief The field of view type of the camera in radians */ float m_PerspectiveFOV = glm::radians(60.0f); /** @brief The projection near and far clip planes of the camera */ float m_PerspectiveNear = 0.1f, m_PerspectiveFar = 10000.0f; /** @brief The orthographic size of the camera */ float m_OrthographicSize = 10.0f; /** @brief The orthographic near and far clip planes of the camera */ float m_OrthographicNear = -1.0f, m_OrthographicFar = 1.0f; friend class EditorUI; friend class Serializer; }; }
BryceStandley/TNAH
core/src/TNAH/Events/Event.h
#pragma once #include <tnahpch.h> namespace tnah { /** * @enum EventType * * @brief Values that represent event types */ enum class EventType { None = 0, WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, AppTick, AppUpdate, AppRender, KeyPressed, KeyReleased, KeyTyped, MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled, DebugApp, DebugCore, MonitorResolutionChange }; /** * @enum EventCategory * * @brief Values that represent event categories */ enum EventCategory { None = 0, EventCategoryApplication = BIT(0), EventCategoryInput = BIT(1), EventCategoryKeyboard = BIT(2), EventCategoryMouse = BIT(3), EventCategoryMouseButton = BIT(4), EventCategoryDebugApp = BIT(5), EventCategoryDebugCore = BIT(6) }; /** * @def EVENT_CLASS_TYPE(type) * * @brief A macro that defines event class type * * @author <NAME> * @date 10/09/2021 * * @param type The type. */ #define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::type; }\ virtual EventType GetEventType() const override { return GetStaticType(); }\ virtual const char* GetName() const override { return #type; } /** * @def EVENT_CLASS_CATEGORY(category) * * @brief A macro that defines event class category * * @author <NAME> * @date 10/09/2021 * * @param category The category. */ #define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; } /** * @class Event * * @brief An base class for all events, handles the type of events and dispatching them to the correct layers or processors for the given event * * @author <NAME> * @date 10/09/2021 */ class Event { public: /** * @fn virtual Event::~Event() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 10/09/2021 */ virtual ~Event() = default; /** @brief True if handled, false if not*/ bool Handled = false; /** * @fn virtual EventType Event::GetEventType() const = 0; * * @brief Pure virtual function used to get the event type * * @author <NAME> * @date 10/09/2021 * * @returns The event type. */ virtual EventType GetEventType() const = 0; /** * @fn virtual const char* Event::GetName() const = 0; * * @brief Pure virtual function used to get the name * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else the name. */ virtual const char* GetName() const = 0; /** * @fn virtual int Event::GetCategoryFlags() const = 0; * * @brief Pure virtual function used to get category flags * * @author <NAME> * @date 10/09/2021 * * @returns The category flags. */ virtual int GetCategoryFlags() const = 0; /** * @fn virtual std::string Event::ToString() const * * @brief Convert this object into a string representation * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ virtual std::string ToString() const { return GetName(); } /** * @fn bool Event::IsInCategory(EventCategory category) * * @brief Query if the given event category is in category * * @author <NAME> * @date 10/09/2021 * * @param category The category. * * @returns True if in category, false if not. */ bool IsInCategory(EventCategory category) { return GetCategoryFlags() & category; } }; /** * @class EventDispatcher * * @brief An event dispatcher class * * @author <NAME> * @date 10/09/2021 */ class EventDispatcher { public: /** * @fn EventDispatcher::EventDispatcher(Event& event) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param [in,out] event The event. */ EventDispatcher(Event& event) : m_Event(event) { } /** * @fn template<typename T, typename F> bool EventDispatcher::Dispatch(const F& func) * * @brief Dispatches the given function * * @tparam T Generic type parameter. * @tparam F Will be deduced by the compiler. * @param func The function. * * @returns True if it succeeds, false if it fails. */ template<typename T, typename F> bool Dispatch(const F& func) { if (m_Event.GetEventType() == T::GetStaticType()) { m_Event.Handled |= func(static_cast<T&>(m_Event)); return true; } return false; } private: Event& m_Event; }; /** * @fn inline std::ostream& operator<<(std::ostream& os, const Event& e) { return os << e.ToString(); * * @brief Stream insertion operator * * @author <NAME> * @date 10/09/2021 * * @param [in,out] os The output stream. * @param e An Event to process. * * @returns The event converted to string representation. */ inline std::ostream& operator<<(std::ostream& os, const Event& e) { return os << e.ToString(); } }
BryceStandley/TNAH
core/src/TNAH/Physics/PhysicsTimestep.h
#pragma once namespace tnah { /** * @class PhysicsTimestep * * @brief The physics timestep class is designed to make sure the frame rate of the physics is 60 frames per second * * @author <NAME> * @date 11/09/2021 */ class PhysicsTimestep { public: PhysicsTimestep() = default; /** * @fn PhysicsTimestep::PhysicsTimestep(float framerate) * * @brief Constructor * * @author <NAME> * @date 11/09/2021 * * @param framerate The framerate. */ PhysicsTimestep(float framerate) : m_TotalTime(0), m_SimSpeed(1.0f/framerate), m_Accumulator(0) {} /** * @fn inline void PhysicsTimestep::AddFrameTime(const float frameTime) * * @brief Adds a frame time * * @author <NAME> * @date 11/09/2021 * * @param frameTime The frame time. */ inline void AddFrameTime(const float frameTime) { m_Accumulator += frameTime; } /** * @fn inline bool PhysicsTimestep::FixedUpdateCheck() const * * @brief Determines if we can fixed update check * * @author <NAME> * @date 11/09/2021 * * @returns True if it succeeds, false if it fails. */ inline bool FixedUpdateCheck() const { return m_Accumulator >= m_SimSpeed; } /** * @fn inline void PhysicsTimestep::Update() * * @brief Updates this object * * @author <NAME> * @date 11/09/2021 */ inline void Update() { m_TotalTime += m_SimSpeed; m_Accumulator -= m_SimSpeed; } /** * @fn float PhysicsTimestep::GetAplha() const * * @brief Gets the aplha * * @author <NAME> * @date 11/09/2021 * * @returns The aplha. */ float GetAplha() const { return m_Accumulator / m_SimSpeed; } /** * @fn void PhysicsTimestep::SetAccumulator(const float a) * * @brief Sets an accumulator * * @author <NAME> * @date 11/09/2021 * * @param a A float to process. */ void SetAccumulator(const float a) { m_Accumulator = a; } /** * @fn float PhysicsTimestep::GetAccumulator() const * * @brief Gets the accumulator * * @author <NAME> * @date 11/09/2021 * * @returns The accumulator. */ float GetAccumulator() const { return m_Accumulator; } /** * @fn void PhysicsTimestep::SetTotalTime(const float time) * * @brief Sets total time * * @author <NAME> * @date 11/09/2021 * * @param time The time. */ void SetTotalTime(const float time) { m_TotalTime = time; } /** * @fn float PhysicsTimestep::GetTotalTime() const * * @brief Gets total time * * @author <NAME> * @date 11/09/2021 * * @returns The total time. */ float GetTotalTime() const { return m_TotalTime; } /** * @fn void PhysicsTimestep::SetSimulationSpeed(const float speed) * * @brief Sets simulation speed * * @author <NAME> * @date 11/09/2021 * * @param speed The speed. */ void SetSimulationSpeed(const float speed) { m_SimSpeed = speed; } /** * @fn void PhysicsTimestep::SetSimulationFrameRate(float frames) * * @brief Sets simulation frame rate * * @author <NAME> * @date 11/09/2021 * * @param frames The frames. */ void SetSimulationFrameRate(float frames) { m_SimSpeed = 1.0f / frames; } /** * @fn float PhysicsTimestep::GetSimulationSpeed() const * * @brief Gets simulation speed * * @author <NAME> * @date 11/09/2021 * * @returns The simulation speed. */ float GetSimulationSpeed() const { return m_SimSpeed; } private: /** @brief The total time */ float m_TotalTime; /** @brief The simulation speed */ float m_SimSpeed; /** @brief The accumulator */ float m_Accumulator; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Ref.h
#pragma once #include <stdint.h> #include <atomic> namespace tnah { /** * @class RefCounted * * @brief A wrapper for shared pointers * * @author <NAME> * @date 7/09/2021 */ class RefCounted { public: /** * * \fn void IncRefCount * * \brief Increase the ref count * * \author <NAME> * \date 13/9/2021 * * * */ void IncRefCount() const { m_RefCount++; } /** * * \fn void DecRefCount * * \brief Decrease the ref count * * \author <NAME> * \date 13/9/2021 * * * */ void DecRefCount() const { m_RefCount--; } /** * * \fn uint32_t GetRefCount * * \brief Get the ref count * * \author <NAME> * \date 13/9/2021 * * * \return * */ uint32_t GetRefCount() const { return m_RefCount.load(); } private: /** @brief The Ref count */ mutable std::atomic<uint32_t> m_RefCount = 0; }; /** * * * \brief Utility Functions * * \author <NAME> * \date 13/9/2021 */ namespace RefUtils { /** * * * \brief Adds to the references list * * \author <NAME> * \date 13/9/2021 */ void AddToLiveReferences(void* instance); /** * * * \brief Removes from the references list * * \author <NAME> * \date 13/9/2021 */ void RemoveFromLiveReferences(void* instance); /** * * * \brief Is the reference live * * \author <NAME> * \date 13/9/2021 */ bool IsLive(void* instance); } template<typename T> class Ref { public: /** * * \fn void Ref * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * * */ Ref() : m_Instance(nullptr) { } /** * * \fn void Ref * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * * */ Ref(std::nullptr_t n) : m_Instance(nullptr) { } /** * * \fn void Ref * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * *@params instance The instance to reference * */ Ref(T* instance) : m_Instance(instance) { static_assert(std::is_base_of<RefCounted, T>::value, "Class is not RefCounted!"); IncRef(); } /** * * \fn void Ref * * \brief Copy constructor of different type * * \author <NAME> * \date 13/9/2021 * * \param other * * */ template<typename T2> Ref(const Ref<T2>& other) { m_Instance = (T*)other.m_Instance; IncRef(); } /** * * \fn void Ref * * \brief Copy constructor of a different type * * \author <NAME> * \date 13/9/2021 * * \param other * * */ template<typename T2> Ref(Ref<T2>&& other) { m_Instance = (T*)other.m_Instance; other.m_Instance = nullptr; } /** * * \fn Ref<T> CopyWithoutIncrement * * \brief Copy reference without increasing the reference count * * \author <NAME> * \date 13/9/2021 * * \param other * * \return Ref<T> Reference of type T * */ static Ref<T> CopyWithoutIncrement(const Ref<T>& other) { Ref<T> result = nullptr; result->m_Instance = other.m_Instance; return result; } /** * * \fn void ~Ref * * \brief Deconstructor * * \author <NAME> * \date 13/9/2021 * * * */ ~Ref() { DecRef(); } /** * * \fn void Ref * * \brief Copy Constructor * * \author <NAME> * \date 13/9/2021 * * \param other * * */ Ref(const Ref<T>& other) : m_Instance(other.m_Instance) { IncRef(); } /** * * \fn Ref & operator= * * \brief Nullptr_t Operator * * \author <NAME> * \date 13/9/2021 * * \param * * \return * */ Ref& operator=(std::nullptr_t) { DecRef(); m_Instance = nullptr; return *this; } /** * * \fn Ref & operator= * * \brief Copy operator * * \author <NAME> * \date 13/9/2021 * * \param other * * \return Ref copy * */ Ref& operator=(const Ref<T>& other) { other.IncRef(); DecRef(); m_Instance = other.m_Instance; return *this; } /** * * \fn Ref & operator= * * \brief Copy operator of different type * * \author <NAME> * \date 13/9/2021 * * \param other * * \return * */ template<typename T2> Ref& operator=(const Ref<T2>& other) { other.IncRef(); DecRef(); m_Instance = other.m_Instance; return *this; } /** * * \fn Ref & operator= * * \brief Copy operator of different type * * \author <NAME> * \date 13/9/2021 * * \param other * * \return * */ template<typename T2> Ref& operator=(Ref<T2>&& other) { DecRef(); m_Instance = other.m_Instance; other.m_Instance = nullptr; return *this; } /** * * \fn int operator bool * * \brief Active operator * * \author <NAME> * \date 13/9/2021 * * * \return bool If the reference instance is not null * */ operator bool() { return m_Instance != nullptr; } /** * * \fn int operator bool * * \brief Active operator * * \author <NAME> * \date 13/9/2021 * * * \return bool If the reference instance is not null * */ operator bool() const { return m_Instance != nullptr; } /** * * \fn T * operator-> * * \brief Pointer operator * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Reference instance * */ T* operator->() { return m_Instance; } /** * * \fn const T * operator-> * * \brief Pointer operator * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Reference instance * */ const T* operator->() const { return m_Instance; } /** * * \fn T & operator* * * \brief Reference operator * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Reference to ref instace * */ T& operator*() { return *m_Instance; } /** * * \fn const T & operator* * * \brief Reference operator * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Reference to ref instace * */ const T& operator*() const { return *m_Instance; } /** * * \fn T * Raw * * \brief Raw instance * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Raw pointer to instance * */ T* Raw() { return m_Instance; } /** * * \fn const T * Raw * * \brief Raw instance * * \author <NAME> * \date 13/9/2021 * * * \return m_Instance Raw pointer to instance * */ const T* Raw() const { return m_Instance; } /** * * \fn void Reset * * \brief Resets the current instance * * \author <NAME> * \date 13/9/2021 * * \param instance * * */ void Reset(T* instance = nullptr) { DecRef(); m_Instance = instance; } /** * * \fn Ref<T2> As * * \brief Reinterprate instance as T2 * * \author <NAME> * \date 13/9/2021 * * * \return this as a reference of type T2 * */ template<typename T2> Ref<T2> As() const { return Ref<T2>(*this); } /** * * \fn Ref<T> Create * * \brief Create template. Calls the constructor on a object of type T * * \author <NAME> * \date 13/9/2021 * * \param ...args * * \return this A new Ref<T> object * */ template<typename... Args> static Ref<T> Create(Args&&... args) { return Ref<T>(new T(std::forward<Args>(args)...)); } /** * * \fn bool operator== * * \brief Compare operator * * \author <NAME> * \date 13/9/2021 * * \param other * * \return bool true if equal, false if not * */ bool operator==(const Ref<T>& other) const { return m_Instance == other.m_Instance; } /** * * \fn bool operator!= * * \brief Compare operator * * \author <NAME> * \date 13/9/2021 * * \param other * * \return bool true if not equal, false if equal * */ bool operator!=(const Ref<T>& other) const { return !(*this == other); } /** * * \fn bool EqualsObject * * \brief Compares this with another object * * \author <NAME> * \date 13/9/2021 * * \param other * * \return bool true if equal, false if not * */ bool EqualsObject(const Ref<T>& other) { if (!m_Instance || !other.m_Instance) return false; return *m_Instance == *other.m_Instance; } private: /** * * \fn void IncRef * * \brief Increase the reference count * * \author <NAME> * \date 13/9/2021 * * * */ void IncRef() const { if (m_Instance) { m_Instance->IncRefCount(); RefUtils::AddToLiveReferences((void*)m_Instance); } } /** * * \fn void DecRef * * \brief Decrease the reference count * * \author <NAME> * \date 13/9/2021 * * * */ void DecRef() const { if (m_Instance) { m_Instance->DecRefCount(); if (m_Instance->GetRefCount() == 0) { delete m_Instance; RefUtils::RemoveFromLiveReferences((void*)m_Instance); m_Instance = nullptr; } } } template<class T2> friend class Ref; /** @brief Instance the reference holds */ mutable T* m_Instance; }; /** * * * \brief Weak reference. Wrapper for weak_ptr * * \author <NAME> * \date 13/9/2021 */ template<typename T> class WeakRef { public: /** * * \fn void WeakRef * * \brief Default constructor * * \author <NAME> * \date 13/9/2021 * * * */ WeakRef() = default; /** * * \fn void WeakRef * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * \param ref * * */ WeakRef(Ref<T> ref) { m_Instance = ref.Raw(); } /** * * \fn void WeakRef * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * \param instance * * */ WeakRef(T* instance) { m_Instance = instance; } /** * * \fn bool IsValid * * \brief Checks if the reference is valid * * \author <NAME> * \date 13/9/2021 * * * \return bool true if valid, false if not * */ bool IsValid() const { return m_Instance ? RefUtils::IsLive(m_Instance) : false; } /** * * \fn int operator bool * * \brief Is Valid operator * * \author <NAME> * \date 13/9/2021 * * * \return bool true if valid, false if not * */ operator bool() const { return IsValid(); } private: /** @brief Instance of the weak ref */ T* m_Instance = nullptr; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Buffer.h
#pragma once #include "TNAH/Core/Core.h" namespace tnah { /** * @struct Buffer * * @brief A buffer struct * * @author <NAME> * @date 7/09/2021 */ struct Buffer { /** @brief A pointer to the data */ void* Data; /** @brief The size */ uint32_t Size; /** * @fn Buffer() * * @brief Default constructor * * @author <NAME> * @date 7/09/2021 */ Buffer() : Data(nullptr), Size(0) { } /** * @fn Buffer(void* data, uint32_t size) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ Buffer(void* data, uint32_t size) : Data(data), Size(size) { } /** * @fn static Buffer Copy(const void* data, uint32_t size) * * @brief Copies this object * * @author <NAME> * @date 7/09/2021 * * @param data The data. * @param size The size. * * @returns A Buffer. */ static Buffer Copy(const void* data, uint32_t size) { Buffer buffer; buffer.Allocate(size); memcpy(buffer.Data, data, size); return buffer; } /** * @fn void Allocate(uint32_t size) * * @brief Allocates the given size * * @author <NAME> * @date 7/09/2021 * * @param size The size. */ void Allocate(uint32_t size) { delete[] Data; Data = nullptr; if (size == 0) return; Data = new byte[size]; Size = size; } /** * @fn void Release() * * @brief Releases this object * * @author <NAME> * @date 7/09/2021 */ void Release() { delete[] Data; Data = nullptr; Size = 0; } /** * @fn void ZeroInitialize() * * @brief Zero initialize * * @author <NAME> * @date 7/09/2021 */ void ZeroInitialize() { if (Data) memset(Data, 0, Size); } /** * @fn template<typename T> T& Read(uint32_t offset = 0) * * @brief Reads the given offset * * @tparam T Generic type parameter. * @param offset (Optional) The offset. * * @returns A reference to a T. */ template<typename T> T& Read(uint32_t offset = 0) { return *(T*)((byte*)Data + offset); } /** * @fn byte* ReadBytes(uint32_t size, uint32_t offset) * * @brief Reads the bytes * * @author <NAME> * @date 7/09/2021 * * @param size The size. * @param offset The offset. * * @returns Null if it fails, else the bytes. */ byte* ReadBytes(uint32_t size, uint32_t offset) { TNAH_CORE_ASSERT(offset + size <= Size, "Buffer overflow!"); byte* buffer = new byte[size]; memcpy(buffer, (byte*)Data + offset, size); return buffer; } /** * @fn void Write(void* data, uint32_t size, uint32_t offset = 0) * * @brief Writes * * @author <NAME> * @date 7/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. * @param offset (Optional) The offset. */ void Write(void* data, uint32_t size, uint32_t offset = 0) { TNAH_CORE_ASSERT(offset + size <= Size, "Buffer overflow!"); memcpy((byte*)Data + offset, data, size); } /** * @fn operator bool() const * * @brief Cast that converts the given to a bool * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator bool() const { return Data; } /** * @fn byte& operator[](int index) * * @brief Array indexer operator * * @author <NAME> * @date 7/09/2021 * * @param index Zero-based index of the. * * @returns The indexed value. */ byte& operator[](int index) { return ((byte*)Data)[index]; } /** * @fn byte operator[](int index) const * * @brief Array indexer operator * * @author <NAME> * @date 7/09/2021 * * @param index Zero-based index of the. * * @returns The indexed value. */ byte operator[](int index) const { return ((byte*)Data)[index]; } /** * @fn template<typename T> T* As() * * @brief Gets data * * @tparam T Generic type parameter. * * @returns Null if it fails, else a pointer to a T. */ template<typename T> T* As() { return (T*)Data; } /** * @fn inline uint32_t GetSize() const * * @brief Gets the size * * @author <NAME> * @date 7/09/2021 * * @returns The size. */ inline uint32_t GetSize() const { return Size; } }; }
BryceStandley/TNAH
core/src/Platform/Windows/WinWindow.h
<reponame>BryceStandley/TNAH #pragma once #include "TNAH/Core/Window.h" #include "TNAH/Events/ApplicationEvent.h" #include "TNAH/Events/MouseEvent.h" #include "TNAH/Events/KeyEvent.h" #include "Platform/OpenGL/OpenGLGraphicsContext.h" #include <GLFW/glfw3.h> namespace tnah { /** * @class WinWindow * * @brief Form for viewing the window. * * @author <NAME> * @date 7/09/2021 */ class WinWindow : public Window { public: /** * @fn WinWindow::WinWindow(const WindowProps& props); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param props The properties. */ WinWindow(const WindowProps& props); /** * @fn virtual WinWindow::~WinWindow(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~WinWindow(); /** * @fn void WinWindow::OnUpdate() override; * * @brief Executes the 'update' action * * @author <NAME> * @date 7/09/2021 */ void OnUpdate() override; /** * @fn inline unsigned int WinWindow::GetWidth() const override * * @brief Gets the width of window * * @author <NAME> * @date 7/09/2021 * * @returns The width. */ inline unsigned int GetWidth() const override { return m_Data.Width; } /** * @fn inline unsigned int WinWindow::GetHeight() const override * * @brief Gets the height of window * * @author <NAME> * @date 7/09/2021 * * @returns The height. */ inline unsigned int GetHeight() const override { return m_Data.Height; } /** * @fn inline void WinWindow::SetEventCallback(const EventCallbackFn& callback) override * * @brief Sets the event callback * * @author <NAME> * @date 7/09/2021 * * @param callback The callback. */ inline void SetEventCallback(const EventCallbackFn& callback) override { m_Data.EventCallback = callback; } /** * @fn void WinWindow::SetVSync(bool enabled) override; * * @brief Sets v synchronize * * @author <NAME> * @date 7/09/2021 * * @param enabled True to enable, false to disable. */ void SetVSync(bool enabled) override; /** * @fn bool WinWindow::IsVSync() const override; * * @brief Query if this object is v synchronize * * @author <NAME> * @date 7/09/2021 * * @returns True if v synchronize, false if not. */ bool IsVSync() const override; /** * @fn inline void* WinWindow::GetNativeWindow() const override * * @brief Gets native window * * @author <NAME> * @date 7/09/2021 * * @returns Null if it fails, else the native window. */ inline void* GetNativeWindow() const override { return m_Window; } /** * @fn inline virtual void WinWindow::SetCursorDisabled(bool disable) override * * @brief Sets cursor status * * @author <NAME> * @date 7/09/2021 * * @param disable True to disable, false to enable. */ inline virtual void SetCursorDisabled(bool disable) override { if(disable) glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); else glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } /** * @fn virtual void WinWindow::ToggleFullScreen(const bool& enabled) override; * * @brief Toggle full screen * * @author <NAME> * @date 7/09/2021 * * @param enabled True to enable, false to disable. */ virtual void ToggleFullScreen(const bool& enabled) override; /** * @fn inline bool WinWindow::IsFullscreen() const override * * @brief Query if this object is fullscreen * * @author <NAME> * @date 7/09/2021 * * @returns True if fullscreen, false if not. */ inline bool IsFullscreen() const override {return m_Data.Fullscreen;} /** * @fn virtual void WinWindow::SetScreenResolution(const uint32_t& width, const uint32_t& height) override; * * @brief Sets screen resolution * * @author <NAME> * @date 7/09/2021 * * @param width The width. * @param height The height. */ virtual void SetScreenResolution(const uint32_t& width, const uint32_t& height) override; private: /** * @fn virtual void WinWindow::Init(const WindowProps& props); * * @brief Initializes this object * * @author <NAME> * @date 7/09/2021 * * @param props The properties. */ virtual void Init(const WindowProps& props); /** * @fn virtual void WinWindow::Shutdown(); * * @brief Shuts down this object and frees any resources it is using * * @author <NAME> * @date 7/09/2021 */ virtual void Shutdown(); private: /** @brief The window */ GLFWwindow* m_Window; /** @brief The context */ GraphicsContext* m_Context; /** * @struct WindowData * * @brief A struct containing Window data. * * @author <NAME> * @date 7/09/2021 */ struct WindowData { /** @brief The title */ std::string Title; /** @brief The window with and height */ unsigned int Width, Height; /** @brief True to synchronize */ bool VSync; /** @brief True to fullscreen */ bool Fullscreen; /** @brief The event callback */ EventCallbackFn EventCallback; }; /** @brief The data */ WindowData m_Data; }; }
BryceStandley/TNAH
core/src/TNAH/Core/FileStructures.h
#pragma once #include <unordered_map> #include "Utility.h" #include <filesystem> namespace tnah { /** * @struct File * * @brief Structure of a file, contains a name and a extension. * * @author <NAME> * @date 7/09/2021 */ struct File { std::string FileName; std::string Extension; std::string FullFile; /** * @fn File() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 7/09/2021 */ File() = default; /** * @fn File(const std::string& name, const std::string& extension) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param name The file name. * @param extension The file extension. */ File(const std::string& name, const std::string& extension) :FileName(name), Extension(extension) { FullFile = FileName + Extension; } /** * @fn operator std::string&() * * @brief Cast that converts the given to a string&amp; * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator std::string&() { return FullFile; } }; /** * @typedef std::string Directory * * @brief Structure of a directory, contains a path. */ typedef std::string Directory; /** * @struct Folder * * @brief Structure of a Folder, contains a vector of files inside a root folder path * * @author <NAME> * @date 7/09/2021 */ struct Folder { /** @brief Pathname of the files in folder */ std::vector<File> FilesInFolder; /** @brief The folder root */ Directory FolderRoot; /** * @fn Folder() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 7/09/2021 */ Folder() = default; }; /** * @struct Project * * @brief Structure of a Project, contains a root directory and vector of sub directories. * * @author <NAME> * @date 7/09/2021 */ struct Project { /** @brief The name */ std::string Name; /** @brief Pathname of the root directory */ Directory RootDirectory; /** @brief The sub directories */ std::vector<Directory> SubDirectories; /** @brief The project files */ std::unordered_map<Directory, Folder> ProjectFiles; /** * @fn Project(const Directory& root) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param root The root. */ Project(const Directory& root) :RootDirectory(root) {} /** * @fn operator std::string&() * * @brief Cast that converts the given to a string&amp; * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator std::string&() { return RootDirectory; } /** * @fn operator std::vector<Directory>&() * * @brief Cast that converts the given to a vector * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator std::vector<Directory>&() { return SubDirectories; } /** * @fn operator std::unordered_map<Directory, Folder>&() * * @brief Gets the folder>&amp; * * @author <NAME> * @date 7/09/2021 * * @returns A std::unordered_map&lt;Directory. */ operator std::unordered_map<Directory, Folder>&() { return ProjectFiles; } }; /** * @enum RType * * @brief Values that represent types */ enum class RType { EMPTY, Unknown, Model, Image, Texture, Shader, Audio, Material, TNAH }; /** * @enum RSubType * * @brief Values that represent sub types */ enum class RSubType { EMPTY, ILLEGAL_SUBTYPE, PBR_Material, Heightmap, UI_Image, Texture_2D, Texture_3D, Vertex_Shader, Fragment_Shader, Audio_Clip, TNAH_Scene, TNAH_Project, TNAH_Resource, TNAH_Prefab }; /** * @struct ResourceType * * @brief A resource type. * * @author <NAME> * @date 7/09/2021 */ struct ResourceType { /** @brief The type */ RType Type = RType::EMPTY; /** @brief The sub type */ RSubType SubType = RSubType::EMPTY; /** * @fn ResourceType() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 7/09/2021 */ ResourceType() = default; /** * @fn ResourceType(const RType& type, const RSubType& subType) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param type The type. * @param subType The subtype. */ ResourceType(const RType& type, const RSubType& subType) :Type(type) { if(type != RType::EMPTY && subType != RSubType::EMPTY) { switch (type) { case RType::Model: // No Subtype for models yet break; case RType::Image: if(subType != RSubType::Heightmap && subType != RSubType::UI_Image) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; case RType::Texture: if(subType != RSubType::Texture_2D && subType != RSubType::Texture_3D) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; case RType::Shader: if(subType != RSubType::Vertex_Shader && subType != RSubType::Fragment_Shader) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; case RType::Audio: if(subType != RSubType::Audio_Clip) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; case RType::Material: if(subType != RSubType::PBR_Material) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; case RType::TNAH: if(subType != RSubType::TNAH_Scene && subType != RSubType::TNAH_Prefab && subType != RSubType::TNAH_Project && subType != RSubType::TNAH_Resource) SubType = RSubType::ILLEGAL_SUBTYPE; else SubType = subType; break; default: SubType = RSubType::EMPTY; break; case RType::EMPTY: break; case RType::Unknown: break; } } } /** * @fn static RType GuessType(const std::string& fileExtension) * * @brief Guess type of the file from its extension * * @author <NAME> * @date 7/09/2021 * * @param fileExtension The file extension. * * @returns A RType. */ static RType GuessType(const std::string& fileExtension) { std::string modelGuess[] = { "fbx", "obj", "c4d", "3ds", "dae" }; std::string imageGuess[] = { "jpg", "png", "tga", "gif", "tiff", "raw", "bmp", "jpeg", "tif", "ktx", "ktx2" }; std::string audioGuess[] = { "mp3", "wav" }; std::string shaderGuess[] = { "glsl", "vert", "frag", "txt" }; std::string materialGuess[] = { "material", "mat", "pbr" }; std::string customGuess[] = { "tnah.scene", "tnahproj", "tnah.resource" , "tnah.meta", "tnah.prefab" }; for(auto s : modelGuess) { if(fileExtension.find(s) != std::string::npos) return RType::Model; } for(auto s : imageGuess) { if(fileExtension.find(s) != std::string::npos) return RType::Image; } for(auto s : audioGuess) { if(fileExtension.find(s) != std::string::npos) return RType::Audio; } for(auto s : shaderGuess) { if(fileExtension.find(s) != std::string::npos) return RType::Shader; } for(auto s : materialGuess) { if(fileExtension.find(s) != std::string::npos) return RType::Material; } for(auto s : customGuess) { if(fileExtension.find(s) != std::string::npos) return RType::TNAH; } return RType::Unknown; } }; /** * @struct Resource * * @brief A resource. * * @author <NAME> * @date 7/09/2021 */ struct Resource { /** @brief CustomName of the resource */ std::string CustomName = ""; /** @brief Pathname of the relative directory */ Directory RelativeDirectory = Directory(""); /** @brief Pathname of the root directory */ Directory RootDirectory = Directory(""); /** @brief Pathname of the absolute directory */ Directory AbsoluteDirectory = Directory(""); /** @brief Filename of the file */ File FileName = File("", ""); /** @brief The type */ ResourceType Type = ResourceType(RType::EMPTY, RSubType::EMPTY); /** * @fn Resource() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 7/09/2021 */ Resource() = default; /** * @fn Resource(const Directory& fileDirectory, const File& fileName, const ResourceType& resourceType) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param fileDirectory Pathname of the file directory. * @param fileName Filename of the file. * @param resourceType Type of the resource. */ Resource(const Directory& fileDirectory, const File& fileName, const ResourceType& resourceType) :RootDirectory(fileDirectory), FileName(fileName), Type(resourceType) { AbsoluteDirectory = RootDirectory + "/" + FileName.FullFile; } /** * @fn Resource(const std::string& fileDirectory, const std::string& fileName, const ResourceType& resourceType) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param fileDirectory Pathname of the file directory. * @param fileName Filename of the file. * @param resourceType Type of the resource. */ Resource(const std::string& fileDirectory, const std::string& fileName, const ResourceType& resourceType) :RootDirectory(fileDirectory), Type(resourceType) { auto n = Utility::SplitFileNameAndExtension(fileName); FileName.FileName = n.first; FileName.Extension = n.second; FileName.FullFile = fileName; AbsoluteDirectory = RootDirectory + "/" + fileName; } /** * @fn Resource(const std::string& relativeFilePath) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param relativeFilePath Full pathname of the relative file. */ Resource(const std::string& relativeFilePath) { if(relativeFilePath.find("\\/") != std::string::npos) { auto dirSplit = Utility::SplitDirectoryAndFilePath(relativeFilePath); RootDirectory = dirSplit.first; FileName.FullFile = dirSplit.second; auto nameSplit = Utility::SplitFileNameAndExtension(dirSplit.second); FileName.FileName = nameSplit.first; FileName.Extension = nameSplit.second; Type.Type = ResourceType::GuessType(FileName.Extension); AbsoluteDirectory = relativeFilePath; RelativeDirectory = Utility::RelativePathFromAbsolute(relativeFilePath); CustomName = nameSplit.first; } else { auto dirSplit = Utility::SplitDirectoryAndFilePath(relativeFilePath); RootDirectory = dirSplit.first; FileName.FullFile = dirSplit.second; auto nameSplit = Utility::SplitFileNameAndExtension(dirSplit.second); FileName.FileName = nameSplit.first; FileName.Extension = nameSplit.second; Type.Type = ResourceType::GuessType(FileName.Extension); AbsoluteDirectory = Utility::AbsolutePathFromRelative(relativeFilePath); RelativeDirectory = relativeFilePath; CustomName = nameSplit.first; } } }; }
BryceStandley/TNAH
core/src/TNAH/Core/Input.h
#pragma once #include "TNAH/Core/Core.h" namespace tnah { /** * @class Input * * @brief An Input * * @author <NAME> * @date 7/09/2021 */ class Input { public: /** * @fn inline static bool Input::IsKeyPressed(int keycode) * * @brief Query if 'keycode' is key pressed * * @author <NAME> * @date 7/09/2021 * * @param keycode The keycode. * * @returns True if key pressed, false if not. */ inline static bool IsKeyPressed(int keycode) { return s_Instance->IsKeyPressedImpl(keycode); } /** * @fn inline static bool Input::IsMouseButtonPressed(int button) * * @brief Query if 'button' is mouse button pressed * * @author <NAME> * @date 7/09/2021 * * @param button The button. * * @returns True if mouse button pressed, false if not. */ inline static bool IsMouseButtonPressed(int button) { return s_Instance->IsMouseButtonPressedImpl(button); } /** * @fn inline static float Input::GetMouseX() * * @brief Gets mouse x coordinate * * @author <NAME> * @date 7/09/2021 * * @returns The mouse x coordinate. */ inline static float GetMouseX() { return s_Instance->GetMouseXImpl(); } /** * @fn inline static float Input::GetMouseY() * * @brief Gets mouse y coordinate * * @author <NAME> * @date 7/09/2021 * * @returns The mouse y coordinate. */ inline static float GetMouseY() { return s_Instance->GetMouseYImpl(); } /** * @fn inline static std::pair<float, float> Input::GetMousePos() * * @brief Gets mouse position * * @author <NAME> * @date 7/09/2021 * * @returns The mouse position. */ inline static std::pair<float, float> GetMousePos() { return s_Instance->GetMousePosImpl(); } protected: /** * @fn virtual bool Input::IsKeyPressedImpl(int keycode) = 0; * * @brief Query if 'keycode' is key pressed implementation * * @author <NAME> * @date 7/09/2021 * * @param keycode The keycode. * * @returns True if key pressed implementation, false if not. */ virtual bool IsKeyPressedImpl(int keycode) = 0; /** * @fn virtual bool Input::IsMouseButtonPressedImpl(int button) = 0; * * @brief Query if 'button' is mouse button pressed implementation * * @author <NAME> * @date 7/09/2021 * * @param button The button. * * @returns True if mouse button pressed implementation, false if not. */ virtual bool IsMouseButtonPressedImpl(int button) = 0; /** * @fn virtual float Input::GetMouseXImpl() = 0; * * @brief Gets mouse x coordinate implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse x coordinate implementation. */ virtual float GetMouseXImpl() = 0; /** * @fn virtual float Input::GetMouseYImpl() = 0; * * @brief Gets mouse y coordinate implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse y coordinate implementation. */ virtual float GetMouseYImpl() = 0; /** * @fn virtual std::pair<float, float> Input::GetMousePosImpl() = 0; * * @brief Gets mouse position implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse position implementation. */ virtual std::pair<float, float> GetMousePosImpl() = 0; private: /** @brief The instance */ static Input* s_Instance; }; }
BryceStandley/TNAH
core/src/TNAH/Physics/Rigidbody.h
#pragma once #include "PhysicsStructures.h" #include "Collider.h" #include "TNAH/Scene/Components/Components.h" namespace tnah::Physics { /** * @class RigidBody * * @brief A class that defines all rigidbody physics body properties. * * @author <NAME> * @date 20/10/2021 * */ class RigidBody : public RefCounted { public: /** * @brief Construct a new Rigid Body object * @author <NAME> * @date 06-11-2021 */ RigidBody(); /** * @brief Construct a new Rigid Body object * @author <NAME> * @date 06-11-2021 */ RigidBody(TransformComponent& transform, BodyMass mass, BodyType type = BodyType::Dynamic); /** * @brief Creates a Ref to a RigidBody object * @author <NAME> * @date 06-11-2021 * @return Ref<RigidBody> */ static Ref<RigidBody> Create(TransformComponent& transform, BodyMass mass, BodyType type = BodyType::Dynamic); /** * @brief Updates the body * @author <NAME> * @date 06-11-2021 */ void OnUpdate(TransformComponent& transform); /** * @brief Get the Body Mass object * @author <NAME> * @date 06-11-2021 * @return BodyMass */ BodyMass GetBodyMass() const { return m_BodyMass; } /** * @brief Adds force to the body (Linear) * @author <NAME> * @date 06-11-2021 */ void AddForce(const glm::vec3& force); /** * @brief Adds torque to the body (Angular) * @author <NAME> * @date 06-11-2021 */ void AddTorque(const glm::vec3& torque); /** * @brief Set the Collision Body object * @author <NAME> * @date 06-11-2021 */ void SetCollisionBody(rp3d::CollisionBody* collisionBody) { m_CollisionBody = collisionBody; } /** * @brief Get the Collision Body object * @author <NAME> * @date 06-11-2021 * @return rp3d::CollisionBody* */ rp3d::CollisionBody* GetCollisionBody() const { return m_CollisionBody; } /** * @brief Adds a collider to the body * @author <NAME> * @date 06-11-2021 */ void AddCollider(Ref<Collider> collider); /** * @brief Get the Colliders objects * @author <NAME> * @date 06-11-2021 * @return std::unordered_map<uint32_t, Ref<Collider>> */ std::unordered_map<uint32_t, Ref<Collider>> GetColliders() { return m_Colliders; } /** * @brief Checks if colliders have been attached to the body * @author <NAME> * @date 06-11-2021 * @return true * @return false */ bool HasColliders() const { return m_TotalColliders > 0 ? true : false; } /** * @fn tnah::Physics::RigidBody::UpdateBodyProperties() * * @brief Updates and recalculates the Local properties of the RigidBody based on its colliders attached. * This overrides any values set. To modify the properties of the body, * address the tnah::Physics::Collider objects directly with RigidBody::GetColliders() * * @author <NAME> * @date Monday, 25 October 2021 * */ void UpdateBodyProperties(); /** * @brief Gets the ID of the body * @author <NAME> * @date 06-11-2021 * @return uint32_t */ uint32_t GetID() const { return m_ID; } /** * @brief Set the Type object * @author <NAME> * @date 06-11-2021 */ void SetType(const BodyType& type) { m_BodyType = type; } /** * @brief Get the Type object * @author <NAME> * @date 06-11-2021 * @return BodyType */ BodyType GetType() const { return m_BodyType; } /** * @brief Get the Inertia Tensor object * @author <NAME> * @date 06-11-2021 * @return InertiaTensor */ InertiaTensor GetInertiaTensor() const { return m_InertiaTensor; } /** * @brief Recalculates the inertia tensor in world space * @author <NAME> * @date 06-11-2021 */ void RecalculateWorldInertiaTensor(); /** * @brief Get the Linear Velocity object * @author <NAME> * @date 06-11-2021 * @return LinearVelocity */ LinearVelocity GetLinearVelocity() const { return m_LinearVelocity; } /** * @brief Get the Angular Velocity object * @author <NAME> * @date 06-11-2021 * @return AngularVelocity */ AngularVelocity GetAngularVelocity() const { return m_AngularVelocity; } /** * @brief Get the Velocities objects * @author <NAME> * @date 06-11-2021 * @return std::pair<LinearVelocity, AngularVelocity> */ std::pair<LinearVelocity, AngularVelocity> GetVelocities() { return {m_LinearVelocity, m_AngularVelocity}; } /** * @brief Set the Linear Rotational Lock Factor object * @author <NAME> * @date 06-11-2021 */ void SetLinearRotationalLockFactor(const glm::ivec3& lock) { m_LinearRotationLock = lock; } /** * @brief Set the Angular Rotational Lock Factor object * @author <NAME> * @date 06-11-2021 */ void SetAngularRotationalLockFactor(const glm::ivec3& lock) { m_AngularRotationLock = lock; } /** * @brief Get the Linear Rotational Lock Factor object * @author <NAME> * @date 06-11-2021 * @return glm::vec3& */ glm::vec3& GetLinearRotationalLockFactor() { return m_LinearRotationLock; } /** * @brief Get the Angular Rotational Lock Factor object * @author <NAME> * @date 06-11-2021 * @return glm::vec3& */ glm::vec3& GetAngularRotationalLockFactor() { return m_AngularRotationLock; } /** * @brief Applies a collision Impulse to the body (Unused) * @author <NAME> * @date 06-11-2021 */ void ApplyCollisionImpulse(const glm::vec3& linearVelocity, const glm::vec3& angularVelocity); /** * @brief Resets the velocity, position and orientation values of the body * @author <NAME> * @date 06-11-2021 */ void ResetValues(); /** * @brief Reference to ignore gravity flag. Used to toggle between ignoring or not ignoring gravity * @author <NAME> * @date 06-11-2021 * @return true * @return false */ bool& IgnoreGravity() { return m_IgnoreGravity; } /** * @brief Checks if the body is sleeping * @author <NAME> * @date 06-11-2021 * @return true * @return false */ bool IsSleeping() const { return m_IsSleeping; } /** * @brief Wakes up the body from sleep * @author <NAME> * @date 06-11-2021 */ void Awake() { m_IsSleeping = false; } /** * @brief Sets a body to sleep * @author <NAME> * @date 06-11-2021 */ void Sleep(); /** * @brief Set the Linear Dampening object, clamping between 0 and 1 * @author <NAME> * @date 06-11-2021 */ void SetLinearDampening(float value) {m_LinearDampening.Dampening = glm::clamp(value, 0.0f, 1.0f);} /** * @brief Set the Angular Dampening object, clamping between 0 and 1 * @author <NAME> * @date 06-11-2021 */ void SetAngularDampening(float value) {m_AngularDampening.Dampening = glm::clamp(value, 0.0f, 1.0f);} /** * @brief Calculates the local inertia tensor * @author <NAME> * @date 06-11-2021 * @return glm::vec3 */ glm::vec3 CalculateLocalInertiaTensor(); private: /** * @brief Calculates the centre of mass of the body * @author <NAME> * @date 06-11-2021 * @return glm::vec3 */ glm::vec3 CalculateCentreOfMass(); /** * @brief Sets the ID of the body * @author <NAME> * @date 06-11-2021 */ void SetID(const uint32_t id) { m_ID = id; } private: /** * @var m_BodyType * * @brief The type of the Rigidbody. Either Dynamic or static. */ BodyType m_BodyType; /** * @var m_BodyMass * * @brief The BodyMass of the Rigidbody. This is the combined total for the whole Rigidbody with all of its Colliders. */ BodyMass m_BodyMass; /** * @var m_LinearVelocity * * @brief The current LinearVelocity of the Rigidbody. */ LinearVelocity m_LinearVelocity; /** * @var m_AngularVelocity * * @brief The current AngularVelocity of the Rigidbody. */ AngularVelocity m_AngularVelocity; /** * @var m_ConstrainedLinearVelocity * * @brief The current Constrained LinearVelocity of the Rigidbody. */ LinearVelocity m_ConstrainedLinearVelocity; /** * @var m_ConstrainedAngularVelocity * * @brief The current Constrained AngularVelocity of the Rigidbody. */ AngularVelocity m_ConstrainedAngularVelocity; /** * @var m_Force * * @brief Current forces applied to the Rigidbody. These are used and zeroed out every PhysicsSystem::OnUpdate(). */ Force m_Force; /** * @var m_Torque * * @brief Current torques applied to the Rigidbody. These are used and zeroed out every PhysicsSystem::OnUpdate(). */ Torque m_Torque; /** * @var m_LinearDampening * * @brief The LinearDampening of the Rigidbody. Values of 0 disable dampening and values of 1 enable full dampening. */ LinearDampening m_LinearDampening; /** * @var m_AngularDampening * * @brief The AngularDampening of the Rigidbody. Values of 0 disable dampening and values of 1 enable full dampening. */ AngularDampening m_AngularDampening; /** * @var m_InertiaTensor * * @brief The InertiaTensor of the Rigidbody with both world and local space data. */ InertiaTensor m_InertiaTensor; /** * @var m_Colliders * * @brief A vector of all colliders on the Rigidbody */ std::unordered_map<uint32_t, Ref<Collider>> m_Colliders; /** * @var m_TotalColliders * @brief Total colliders attached to the body * @author <NAME> * @date 06-11-2021 */ uint32_t m_TotalColliders = 0; /** * @var m_ID * * @brief The global ID of the RigidBody. */ uint32_t m_ID = 0; /** * @var m_LinearRotationLock * * @brief Rotational lock factor for linear velocities. 1 is enabled, 0 is disabled per axis. */ glm::vec3 m_LinearRotationLock = {1,1,1}; /** * @var m_AngularRotationLock * * @brief Rotational lock factor for angular velocities. 1 is enabled, 0 is disabled per axis. */ glm::vec3 m_AngularRotationLock = {1,1,1}; /** * @var m_Position * @brief World position of the body * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_Position = {0,0,0}; /** * @var m_Orientation * @brief World orientation of the body * @author <NAME> * @date 06-11-2021 */ glm::quat m_Orientation = {0,0,0,0}; /** * @var m_IsSleeping * * @brief A flag to note if the RigidBody is currently sleeping thus not being simulated. */ bool m_IsSleeping = false; /** * @var m_SleepVelocityThreshold * @brief Threshold to sleep based on velocity * @author <NAME> * @date 06-11-2021 */ float m_SleepVelocityThreshold = 0.2f; /** * @var m_SleepTimeThreshold * @brief Threshold to sleep based on time * @author <NAME> * @date 06-11-2021 */ float m_SleepTimeThreshold = 1.0f; /** * @var m_SleepTimeAccumulator * @brief Accumulator of time when the body reached the threshold velocity to sleep * @author <NAME> * @date 06-11-2021 */ float m_SleepTimeAccumulator = 0.0f; /** * @var m_IgnoreGravity * * @brief A flag to note if the RigidBody should ignore gravity within the world. */ bool m_IgnoreGravity = false; /** * @var m_CollisionBody * * @brief The Reactphysics3d Collision body used by the Rigidbody to interact and move within the PhysicsWorld. */ rp3d::CollisionBody* m_CollisionBody = nullptr; friend class PhysicsEngine; friend class EditorUI; friend class Serializer; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AnimatorComponent.h
#pragma once #include "TNAH/Renderer/Animation.h" namespace tnah { /**********************************************************************************************//** * @class AnimatorComponent * * @brief An animator component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class AnimatorComponent { public: /**********************************************************************************************//** * @fn AnimatorComponent::AnimatorComponent(); * * @brief Default constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ AnimatorComponent(); /**********************************************************************************************//** * @fn AnimatorComponent::AnimatorComponent(const Animation& animation); * * @brief Copy Constructor * * @author Chris * @date 10/09/2021 * * @param animation The animation. **************************************************************************************************/ AnimatorComponent(const Animation& animation); /**********************************************************************************************//** * @fn void AnimatorComponent::UpdateAnimation(float dt); * * @brief Updates the animation dictated by deltaTime (dt) * * @author Chris * @date 10/09/2021 * * @param dt The deltaTime **************************************************************************************************/ void UpdateAnimation(float dt); /**********************************************************************************************//** * @fn void AnimatorComponent::PlayAnimation(const Animation& animation); * * @brief Plays animation * * @author Chris * @date 10/09/2021 * * @param animation The animation component. **************************************************************************************************/ void PlayAnimation(const Animation& animation); /**********************************************************************************************//** * @fn std::vector<glm::mat4> AnimatorComponent::GetFinalBonesMatrices() const * * @brief Gets final bones matrices * * @author Chris * @date 10/09/2021 * * @returns The final bones matrices. **************************************************************************************************/ std::vector<glm::mat4> GetFinalBonesMatrices() const { return m_FinalBoneMatrices; }; private: /**********************************************************************************************//** * @fn void AnimatorComponent::CalculateBoneTransform(const AssimpNodeData* node, glm::mat4 parentTransform); * * @brief Calculates the bone transform * * @author Chris * @date 10/09/2021 * * @param node The node. * @param parentTransform The parent transform. **************************************************************************************************/ void CalculateBoneTransform(const AssimpNodeData* node, glm::mat4 parentTransform); private: /** @brief The final bone matrices */ std::vector<glm::mat4> m_FinalBoneMatrices; /** @brief The current animation */ Animation m_CurrentAnimation; /** @brief The current time */ float m_CurrentTime = 0; /** @brief The delta time */ float m_DeltaTime = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/Emotion.h
<filename>core/src/TNAH/Scene/Components/AI/Emotion.h #pragma once namespace tnah { /** * @brief each emotional state is represented in this enum class */ enum class Emotion { Neutral = 0, Excited, Delighted, Happy, // High Arousal - Positive Valence Content, Relaxed, Calm, // Low Arousal - Positive Valence Tense, Angry, Frustrated, // High Arousal - Negative Valence Depressed, Bored, Tired, // Low Arousal - Negative Valence }; /** * @fn inline std::ostream& operator<<(std::ostream& os, Emotion e) * * @brief Used to allow for the printing of Emotion states * * @author <NAME> * @date 2/11/2021 * * @param os - output stream object * @param e - refers to the Emotion states * @return - output stream */ inline std::ostream& operator<<(std::ostream& os, Emotion e) { switch (e) { case Emotion::Happy: return os << "Happy"; case Emotion::Delighted: return os << "Delighted"; case Emotion::Excited: return os << "Excited"; case Emotion::Calm: return os << "Calm"; case Emotion::Relaxed: return os << "Relaxed"; case Emotion::Content: return os << "Content"; case Emotion::Frustrated: return os << "Frustrated"; case Emotion::Angry: return os << "Angry"; case Emotion::Tense: return os << "Tense"; case Emotion::Tired: return os << "Tired"; case Emotion::Bored: return os << "Bored"; case Emotion::Depressed: return os << "Depressed"; default: return os << "Neutral"; } } /** * @enum Mood * * @brief each mood state is represented in this enum class */ enum class Mood { Neutral = 0, Happy, // High Arousal - Positive Valence Angry, // High Arousal - Negative Valence Sad, // Low Arousal - Negative Valence Relaxed // Low Arousal - Positive Valence }; /** * @fn inline std::ostream& operator<<(std::ostream& os, Mood m) * * @brief Used to allow for the printing of Mood states * * @author <NAME> * @date 2/11/2021 * * @param os - output stream object * @param m - refers to the Mood states * @return - output stream */ inline std::ostream& operator<<(std::ostream& os, Mood m) { switch (m) { case Mood::Happy: return os << "Happy"; case Mood::Angry: return os << "Delighted"; case Mood::Sad: return os << "Excited"; case Mood::Relaxed: return os << "Calm"; default: return os << "Neutral"; } } /** * @enum Trait * * @brief each character trait is represented in this enum class */ enum class Trait { Neutral, Cheerful, Delighted, Happy, // High Arousal - Positive Valence Depressed, Bland, Sad, // Low Arousal - Negative Valence Carefree, Peaceful, Patient, // Low Arousal - Positive Valence Paranoid, Aggressive, Impatient // High Arousal - Negative Valence }; /** * @fn inline std::ostream& operator<<(std::ostream& os, Trait t) * * @brief Used to allow for the printing of character traits * * @author <NAME> * @date 2/11/2021 * * @param os - output stream object * @param t - refers to the character Traits * @return - output stream */ inline std::ostream& operator<<(std::ostream& os, Trait t) { switch (t) { case Trait::Happy: return os << "Happy"; case Trait::Delighted: return os << "Delighted"; case Trait::Cheerful: return os << "Cheerful"; case Trait::Sad: return os << "Sad"; case Trait::Bland: return os << "Bland"; case Trait::Depressed: return os << "Depressed"; case Trait::Patient: return os << "Patient"; case Trait::Peaceful: return os << "Peaceful"; case Trait::Carefree: return os << "Carefree"; case Trait::Impatient: return os << "Impatient"; case Trait::Aggressive: return os << "Aggressive"; case Trait::Paranoid: return os << "Paranoid"; default: return os << "Neutral"; } } }
BryceStandley/TNAH
core/src/TNAH/Core/Singleton.h
<gh_stars>1-10 #pragma once namespace tnah { /** * @class singleton * @brief A templated class that uses the singleton design pattern to provide one instance of any specified class. * * @author <NAME> * @version 01 * @date 30/03/2021 <NAME>, Started * * **/ template<class T> class singleton { public: /** * @brief gets and returns the instance of the class provided to the singleton * @return static instance of the given class * */ static T& getInstance() { static T instance; return instance; } private: /** * @brief default constructor * */ singleton() {} /** * @brief destructor * */ ~singleton() {} /// Singletons shouldn't be cloneable singleton(singleton const&) = delete; /// Singletons shouldn't be assignable singleton& operator=(singleton const&) = delete; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Log.h
#pragma once #include "Core.h" #pragma warning(push, 0) #include <memory> #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE //#define SPDLOG_FUNCTION #include <spdlog/spdlog.h> #include <spdlog/sinks/stdout_color_sinks.h> #include "spdlog/fmt/ostr.h" #pragma warning(pop) namespace tnah { /** * @class Log * * @brief A logging class that handles loggers for the core engine and the client * * @author <NAME> * @date 7/09/2021 */ class Log { public: /** * @fn static void Log::Init(); * * @brief Initializes this object * * @author <NAME> * @date 7/09/2021 */ static void Init(); /** * @fn static void Log::SetLoggerDebugMode(); * * @brief Changes the Output of the logger to also display extra debug infomation * * @author <NAME> * @date 7/09/2021 */ static void SetLoggerDebugMode(); /** * @fn static void Log::SetLoggerCoreMode(); * * @brief Changes the Output of the logger to also display extra debug infomation * * @author <NAME> * @date 7/09/2021 */ static void SetLoggerCoreMode(); /** * @fn inline static std::shared_ptr<spdlog::logger>& Log::GetCoreLogger() * * @brief Gets core logger * * @author <NAME> * @date 7/09/2021 * * @returns The core logger. */ inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; } /** * @fn inline static std::shared_ptr<spdlog::logger>& Log::GetClientLogger() * * @brief Gets client logger * * @author <NAME> * @date 7/09/2021 * * @returns The client logger. */ inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; } private: /** @brief The core logger */ static std::shared_ptr<spdlog::logger> s_CoreLogger; /** @brief The client logger */ static std::shared_ptr<spdlog::logger> s_ClientLogger; }; } // Core log macros #define TNAH_CORE_TRACE(...) SPDLOG_LOGGER_TRACE(::tnah::Log::GetCoreLogger(), __VA_ARGS__) // White #define TNAH_CORE_INFO(...) SPDLOG_LOGGER_INFO(::tnah::Log::GetCoreLogger(), __VA_ARGS__)// Green #define TNAH_CORE_WARN(...) SPDLOG_LOGGER_WARN(::tnah::Log::GetCoreLogger(), __VA_ARGS__) // Yellow #define TNAH_CORE_ERROR(...) SPDLOG_LOGGER_ERROR(::tnah::Log::GetCoreLogger(), __VA_ARGS__) // Red #define TNAH_CORE_FATAL(...) SPDLOG_LOGGER_CRITICAL(::tnah::Log::GetCoreLogger(), __VA_ARGS__) // White with red highlight // Client log macros #define TNAH_TRACE(...) SPDLOG_LOGGER_TRACE(::tnah::Log::GetClientLogger(), __VA_ARGS__) #define TNAH_INFO(...) SPDLOG_LOGGER_INFO(::tnah::Log::GetClientLogger(), __VA_ARGS__) #define TNAH_WARN(...) SPDLOG_LOGGER_WARN(::tnah::Log::GetClientLogger(), __VA_ARGS__) #define TNAH_ERROR(...) SPDLOG_LOGGER_ERROR(::tnah::Log::GetClientLogger(), __VA_ARGS__) #define TNAH_FATAL(...) SPDLOG_LOGGER_CRITICAL(::tnah::Log::GetClientLogger(), __VA_ARGS__)
BryceStandley/TNAH
core/src/TNAH/Scene/Components/SkyboxComponent.h
#pragma once #include "TNAH/Core/Core.h" #include <glm/glm.hpp> #include "ComponentIdentification.h" #include "TNAH/Renderer/RenderingBuffers.h" #include "TNAH/Renderer/Material.h" #include "TNAH/Renderer/VertexArray.h" #include "TNAH/Renderer/Texture.h" namespace tnah { /**********************************************************************************************//** * @class Skybox * * @brief A skybox. * * @author <NAME>, Dylan * @date 10/09/2021 **************************************************************************************************/ class Skybox { public: /**********************************************************************************************//** * @fn Skybox::Skybox(); * * @brief Default constructor * * @author <NAME>, Dylan * @date 10/09/2021 **************************************************************************************************/ Skybox(); /**********************************************************************************************//** * @fn Skybox::Skybox(const Texture3DProperties& skyboxTextureProperties); * * @brief Constructor * * @author <NAME>, Dylan * @date 10/09/2021 * * @param skyboxTextureProperties The skybox texture properties. **************************************************************************************************/ Skybox(const Texture3DProperties& skyboxTextureProperties); /**********************************************************************************************//** * @fn float* Skybox::GetVBOData() * * @brief Gets vbo data * * @author <NAME>, Dylan * @date 10/09/2021 * * @returns Null if it fails, else the vbo data. **************************************************************************************************/ float* GetVBOData() { return &m_VBOData[0]; } /**********************************************************************************************//** * @fn uint32_t Skybox::GetVBODataSize() * * @brief Gets vbo data size * * @author <NAME>, Dylan * @date 10/09/2021 * * @returns The vbo data size. **************************************************************************************************/ uint32_t GetVBODataSize() { return m_VBOSize; } /**********************************************************************************************//** * @fn inline Ref<VertexArray> Skybox::GetVertexArray() * * @brief Gets vertex array * * @author <NAME>, Dylan * @date 10/09/2021 * * @returns The vertex array. **************************************************************************************************/ inline Ref<VertexArray> GetVertexArray() { return m_VAO; } /**********************************************************************************************//** * @fn inline Ref<VertexBuffer> Skybox::GetVertexBuffer() * * @brief Gets vertex buffer * * @author <NAME>, Dylan * @date 10/09/2021 * * @returns The vertex buffer. **************************************************************************************************/ inline Ref<VertexBuffer> GetVertexBuffer() { return m_VBO; } /**********************************************************************************************//** * @fn inline Ref<SkyboxMaterial> Skybox::GetMaterial() * * @brief Gets the material * * @author <NAME>, Dylan * @date 10/09/2021 * * @returns The material. **************************************************************************************************/ inline Ref<SkyboxMaterial> GetMaterial() { return m_Material; } private: /**********************************************************************************************//** * @fn void Skybox::Create(); * * @brief Creates this object * * @author <NAME>, Dylan * @date 10/09/2021 **************************************************************************************************/ void Create(); /** @brief The vao */ Ref<VertexArray> m_VAO; /** @brief The vbo */ Ref<VertexBuffer> m_VBO; /** @brief The buffer layout */ VertexBufferLayout m_BufferLayout; /** @brief The material */ Ref<SkyboxMaterial> m_Material; /** @brief The skybox texture */ Ref<Texture3D> m_SkyboxTexture; /** @brief Information describing the vbo */ std::vector<float> m_VBOData; /** @brief Size of the vbo */ uint32_t m_VBOSize = 0; private: friend class Scene; friend class SkyboxComponent; }; /**********************************************************************************************//** * @class SkyboxComponent * * @brief A skybox component. * * @author <NAME>, Dylan * @date 10/09/2021 **************************************************************************************************/ class SkyboxComponent { public: /** @brief The scene skybox */ Skybox* SceneSkybox; /**********************************************************************************************//** * @fn SkyboxComponent::SkyboxComponent() * * @brief Default constructor * * @author <NAME>, Dylan * @date 10/09/2021 **************************************************************************************************/ SkyboxComponent() { SceneSkybox = new Skybox(); } /**********************************************************************************************//** * @fn SkyboxComponent::SkyboxComponent(const SkyboxComponent& other) = default; * * @brief Defaulted copy constructor * * @author <NAME>, Dylan * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ SkyboxComponent(const SkyboxComponent& other) = default; /**********************************************************************************************//** * @fn SkyboxComponent::SkyboxComponent(const Texture3DProperties& cubemapProperties) * * @brief Constructor * * @author <NAME>, Dylan * @date 10/09/2021 * * @param cubemapProperties The cubemap properties. **************************************************************************************************/ SkyboxComponent(const Texture3DProperties& cubemapProperties) { SceneSkybox = new Skybox(cubemapProperties); } private: friend class EditorUI; inline static std::string s_SearchString = "skybox component"; inline static ComponentTypes s_Types = { {ComponentVariations::Skybox}, {{ComponentCategory::Core, ComponentCategory::Rendering, ComponentCategory::Environment}} }; }; }
BryceStandley/TNAH
core/src/Platform/OpenGL/OpenGLGraphicsContext.h
#pragma once #include "TNAH/Renderer/GraphicsContext.h" /** * @struct GLFWwindow * * @brief Form for viewing the glfw. * * @author <NAME> * @date 7/09/2021 */ struct GLFWwindow; namespace tnah { /** * @class OpenGLGraphicsContext * * @brief An OpenGlGraphicsContext class that inherbits from a base GraphicsContext. * * @author <NAME> * @date 7/09/2021 */ class OpenGLGraphicsContext : public GraphicsContext { public: /** * @fn OpenGLGraphicsContext::OpenGLGraphicsContext(GLFWwindow* window); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] window A pointer to the GLFWwindow. */ OpenGLGraphicsContext(GLFWwindow* window); /** * @fn void OpenGLGraphicsContext::Init() override; * * @brief Initializes GLFW * * @author <NAME> * @date 7/09/2021 */ void Init() override; /** * @fn void OpenGLGraphicsContext::SwapBuffers() override; * * @brief Swap buffers * * @author <NAME> * @date 7/09/2021 */ void SwapBuffers() override; private: /** @brief The GLFW window */ GLFWwindow* m_Window; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/PhysicsComponents.h
<gh_stars>1-10 #pragma once #include "TNAH/Physics/PhysicsEngine.h" #include "TNAH/Renderer/Mesh.h" #include "ComponentIdentification.h" namespace tnah{ class GameObject; /**********************************************************************************************//** * @class RigidBodyComponent * * @brief A physics rigidbody allows physics to be simulated on a object * * @author <NAME> * @date 20/07/2021 * * @author <NAME> * @date 05/09/2021 **************************************************************************************************/ struct RigidBodyComponent { Ref<Physics::RigidBody> Body = nullptr; /** @brief True to edit */ bool Edit = false; /** @brief True to use edit */ bool UseEdit = false; /**********************************************************************************************//** * @fn RigidBodyComponent::RigidBodyComponent(); * * @brief Default constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ RigidBodyComponent(); /**********************************************************************************************//** * @fn RigidBodyComponent::RigidBodyComponent(const RigidBodyComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ RigidBodyComponent(const RigidBodyComponent& other) = default; /**********************************************************************************************//** * @fn RigidBodyComponent(GameObject& gameObject, const Physics::BodyType& type = Physics::BodyType::Dynamic); * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param gameObject * @param type The type. **************************************************************************************************/ RigidBodyComponent(GameObject& gameObject, const Physics::BodyType& type = Physics::BodyType::Dynamic); /**********************************************************************************************//** * @fn RigidBodyComponent::void OnUpdate(const TransformComponent& transform); * * @brief Update function for the Rigidbody component. Updates the Rigidbody with the current transform and orientation. * * @author <NAME> * @date 10/10/2021 * **************************************************************************************************/ void OnUpdate(TransformComponent& transform); /**********************************************************************************************//** * @fn void ApplyForce(const glm::vec3& direction, const glm::vec3& force); * * @brief Applies the force * * @author Chris * @date 10/09/2021 * * @param direction The direction. * @param force The force. **************************************************************************************************/ void ApplyForce(const glm::vec3& direction, const glm::vec3& force); /**********************************************************************************************//** * @fn void ApplyTorque(const glm::vec3& direction, const glm::vec3& torque); * * @brief Applies the torque described by torque * * @author Chris * @date 10/09/2021 * * @param torque The torque. **************************************************************************************************/ void ApplyTorque(const glm::vec3& direction, const glm::vec3& torque); /** * @fn Ref<Physics::Collider> AddCollider(const glm::vec3& boxSize); * * @brief Adds a collider to the current active rigidbody on the component. * * @author <NAME> * @date Thursday, 14 October 2021 * * @param boxSize Full size of each dimension of the box * * @returns Collider Ref or nullptr if adding the collider failed. * */ Ref<Physics::Collider> AddCollider(const glm::vec3& boxSize); /** * @fn Ref<Physics::Collider> AddCollider(const glm::vec3& boxSize, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); * * @brief Adds a collider with set values * * @author <NAME> * @date 6/11/2021 * * @param boxSize * @param localPosition * @param localOrientation * @param density * @param volume * @return * */ Ref<Physics::Collider> AddCollider(const glm::vec3& boxSize, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); /** * @fn Ref<Physics::Collider> AddCollider(const float& sphereRadius); * * @brief Adds a collider to the current active rigidbody on the component. * * @author <NAME> * @date Thursday, 14 October 2021 * * @param sphereRadius The radius of the sphere * * @returns Collider Ref or nullptr if adding the collider failed. * */ Ref<Physics::Collider> AddCollider(const float& sphereRadius); /** * @fn Ref<Physics::Collider> AddCollider(const float& sphereRadius, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); * * @brief Adds a sphere collider with set values * * @author <NAME> * @date 6/11/2021 * * @param sphereRadius * @param localPosition * @param localOrientation * @param density * @param volume * @return * */ Ref<Physics::Collider> AddCollider(const float& sphereRadius, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); /** * @fn Ref<Physics::Collider> AddCollider(const float& capsuleRadius, const float& capsuleHeight); * * @brief Adds a collider to the current active rigidbody on the component. * * @author <NAME> * @date Thursday, 14 October 2021 * * @param capsuleRadius The radius of the capsule * @param capsuleHeight The height of the capsule * * @returns Collider Ref or nullptr if adding the collider failed. * */ Ref<Physics::Collider> AddCollider(const float& capsuleRadius, const float& capsuleHeight); /** * @fn Ref<Physics::Collider> AddCollider(const float& capsuleRadius, const float& capsuleHeight, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); * * @brief Adds a capsule collider with set values * * @author <NAME> * @date 6/11/2021 * * @param capsuleRadius * @param capsuleHeight * @param localPosition * @param localOrientation * @param density * @param volume * @return * */ Ref<Physics::Collider> AddCollider(const float& capsuleRadius, const float& capsuleHeight, const glm::vec3& localPosition, const glm::quat& localOrientation, const float& density, const float& volume); private: /** @brief Search string for the component in the editor */ inline static std::string s_SearchString = "rigidbody component"; /** @brief Component search types and groupings */ inline static ComponentTypes s_Types = { {ComponentVariations::Rigidbody}, {{ComponentCategory::Physics}} }; friend class EditorUI; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Math.h
<filename>core/src/TNAH/Core/Math.h #pragma once #define USE_MATH_DEFINES #include "TNAH/Core/Core.h" #pragma warning(push, 0) #define GLM_ENABLE_EXPERIMENTAL #include <glm/gtx/matrix_decompose.hpp> #include <glm/gtx/norm.hpp> #include <glm/gtx/quaternion.hpp> #include <corecrt_math_defines.h> #include <IrrKlang/irrKlang.h> #include "imgui.h" #include "glm/glm.hpp" #include "reactphysics3d/reactphysics3d.h" #include "TNAH/Scene/Components/Components.h" #pragma warning(pop) namespace tnah { struct LogText { LogText(std::string s = "", glm::vec4 vec = glm::vec4(1)) : text(s), colour(vec) {} std::string text; glm::vec4 colour; }; namespace Math { /** * @fn inline float BiLinearInterpolate(float a, float b, float blend) * * @brief Bi linear interpolate * * @author <NAME> * @date 7/09/2021 * * @param a A float to process. * @param b A float to process. * @param blend The blend. * * @returns A float. */ inline float BiLinearInterpolate(float a, float b, float blend) { double theta = blend * M_PI; float f = static_cast<float>(1.0f - cos(theta)) * 0.5f; return a * (1.0f - f) + b * f; } /** * @fn bool DecomposeTransform(const glm::mat4& transform, glm::vec3& translation, glm::vec3& rotation, glm::vec3& scale); * * @brief Decompose transform * * @author <NAME> * @date 7/09/2021 * * @param transform The transform. * @param [in,out] translation The translation. * @param [in,out] rotation The rotation. * @param [in,out] scale The scale. * * @returns True if it succeeds, false if it fails. */ bool DecomposeTransform(const glm::mat4& transform, glm::vec3& translation, glm::vec3& rotation, glm::vec3& scale); /** * @fn inline bool CompareImGuiToGLM(const ImVec2& imgui, const glm::vec2& glm) * * @brief Compare imgui vec2 to glm vec2 * * @author <NAME> * @date 7/09/2021 * * @param imgui The imgui. * @param glm The glm. * * @returns True if it succeeds, false if it fails. */ inline bool CompareImGuiToGLM(const ImVec2& imgui, const glm::vec2& glm) { if(static_cast<int>(imgui.x) == static_cast<int>(glm.x) && static_cast<int>(imgui.y) == static_cast<int>(glm.y)) return true; return false; } /** * @fn inline bool CompareImVec2(const ImVec2& a, const ImVec2 b) * * @brief Compare imgui vec2 * * @author <NAME> * @date 7/09/2021 * * @param a An ImVec2 to process. * @param b An ImVec2 to process. * * @returns True if it succeeds, false if it fails. */ inline bool CompareImVec2(const ImVec2& a, const ImVec2 b) { if(static_cast<int>(a.x) == static_cast<int>(b.x) && static_cast<int>(a.y) == static_cast<int>(b.y)) return true; return false; } /** * @fn static float Remap(float value, float oldMin, float oldMax, float newMin, float newMax) * * @brief Remaps the range * * @author <NAME> * @date 7/09/2021 * * @param value The value. * @param oldMin The old minimum. * @param oldMax The old maximum. * @param newMin The new minimum. * @param newMax The new maximum. * * @returns A float. */ static float Remap(float value, float oldMin, float oldMax, float newMin, float newMax) { return newMin + (newMax - newMin) * ((value - oldMin) / (oldMax - oldMin)); } /** * @fn irrklang::vec3df ConvertVec3ToVec3df(const glm::vec3& other); * * @brief Convert glm vec3 to irrklang vec3df * * @author <NAME> * @date 7/09/2021 * * @param other The other. * * @returns The vector converted 3 to vector 3df. */ irrklang::vec3df ConvertVec3ToVec3df(const glm::vec3& other); /** * @fn static rp3d::Vector3 ToRp3dVec3(const glm::vec3& values) * * @brief Converts the glm vec3 values to a rp3D vector 3 values * * @author <NAME> * @date 7/09/2021 * * @param values The values. * * @returns Values as a rp3d::Vector3. */ static rp3d::Vector3 ToRp3dVec3(const glm::vec3& values) { return rp3d::Vector3(values.x, values.y, values.z); } /** * @fn static glm::vec3 FromRp3dVec3(const rp3d::Vector3& values) * * @brief Converts the reactphysics3d vector3 values to a glm vec3 values * * @author <NAME> * @date 7/09/2021 * * @param values The values. * * @returns Values as a glm::vec3. */ static glm::vec3 FromRp3dVec3(const rp3d::Vector3& values) { return glm::vec3(values.x, values.y, values.z); } /** * @fn static rp3d::Quaternion ToRp3dQuat(const glm::quat& values) * * @brief Converts the glm quaternion values to a rp3D quaternion * * @author <NAME> * @date 7/09/2021 * * @param values The values. * * @returns Values as a rp3d::Quaternion. */ static rp3d::Quaternion ToRp3dQuat(const glm::quat& values) { return rp3d::Quaternion(values.x, values.y, values.z, values.w); } /** * @fn static glm::quat FromRp3dQuat(const rp3d::Quaternion& values) * * @brief Converts the Rp3d quaternion values to a glm quaternion * * @author <NAME> * @date 7/09/2021 * * @param values The values. * * @returns Values as a glm::quat */ static glm::quat FromRp3dQuat(const rp3d::Quaternion& values) { return glm::quat(values.w, values.x, values.y, values.z); } /** * @fn static rp3d::Transform ToRp3dTransform(const TransformComponent& transform) * * @brief Converts a TranformComponent transform to a rp3d transform * * @author <NAME> * @date 7/09/2021 * * @param transform The transform. * * @returns Transform as a rp3d::Transform. */ static rp3d::Transform ToRp3dTransform(const TransformComponent& transform) { return rp3d::Transform(ToRp3dVec3(transform.Position), ToRp3dQuat(glm::quat(transform.Rotation))); } /** * @fn static float Random() * * @brief Gets the random * * @author <NAME> * @date 7/09/2021 * * @returns A float. */ static float Random() { float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); return r; } /** * @fn static float Random(const float& max) * * @brief Randoms the given maximum * * @author <NAME> * @date 7/09/2021 * * @param max The maximum. * * @returns A float. */ static float Random(const float& max) { float r2 = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/max)); return r2; } /** * @fn static float Random(const float& min, const float& max) * * @brief Randoms the min and max values * * @author <NAME> * @date 7/09/2021 * * @param min The minimum. * @param max The maximum. * * @returns A float. */ static float Random(const float& min, const float& max) { float r3 = min + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(max-min))); return r3; } } }
BryceStandley/TNAH
core/src/TNAH/Events/ApplicationEvent.h
#pragma once #include <sstream> #include "TNAH/Events/Event.h" namespace tnah { /** * @class WindowResizeEvent * * @brief A window resize event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class WindowResizeEvent : public Event { public: /** * @fn WindowResizeEvent::WindowResizeEvent(unsigned int width, unsigned int height) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param width The width. * @param height The height. */ WindowResizeEvent(unsigned int width, unsigned int height) : m_Width(width), m_Height(height) {} /** * @fn unsigned int WindowResizeEvent::GetWidth() const * * @brief Gets the width * * @author <NAME> * @date 10/09/2021 * * @returns The width. */ unsigned int GetWidth() const { return m_Width; } /** * @fn unsigned int WindowResizeEvent::GetHeight() const * * @brief Gets the height * * @author <NAME> * @date 10/09/2021 * * @returns The height. */ unsigned int GetHeight() const { return m_Height; } /** * @fn std::string WindowResizeEvent::ToString() const override * * @brief Convert this object into a string representation * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ std::string ToString() const override { std::stringstream ss; ss << "WindowResizeEvent: " << m_Width << ", " << m_Height; return ss.str(); } EVENT_CLASS_TYPE(WindowResize) EVENT_CLASS_CATEGORY(EventCategoryApplication) private: /** @brief The width of the window */ unsigned int m_Width; /** @brief The height of the window */ unsigned int m_Height; }; /** * @class WindowCloseEvent * * @brief A window close event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class WindowCloseEvent : public Event { public: /** * @fn WindowCloseEvent::WindowCloseEvent() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 */ WindowCloseEvent() = default; EVENT_CLASS_TYPE(WindowClose) EVENT_CLASS_CATEGORY(EventCategoryApplication) }; /** * @class AppTickEvent * * @brief An application tick event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class AppTickEvent : public Event { public: /** * @fn AppTickEvent::AppTickEvent() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 */ AppTickEvent() = default; EVENT_CLASS_TYPE(AppTick) EVENT_CLASS_CATEGORY(EventCategoryApplication) }; /** * @class AppUpdateEvent * * @brief An application update event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class AppUpdateEvent : public Event { public: /** * @fn AppUpdateEvent::AppUpdateEvent() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 */ AppUpdateEvent() = default; EVENT_CLASS_TYPE(AppUpdate) EVENT_CLASS_CATEGORY(EventCategoryApplication) }; /** * @class AppRenderEvent * * @brief An application render event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class AppRenderEvent : public Event { public: /** * @fn AppRenderEvent::AppRenderEvent() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 */ AppRenderEvent() = default; EVENT_CLASS_TYPE(AppRender) EVENT_CLASS_CATEGORY(EventCategoryApplication) }; /** * @class MonitorResolutionChangeEvent * * @brief A monitor resolution change event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class MonitorResolutionChangeEvent: public Event { public: /** * @fn MonitorResolutionChangeEvent::MonitorResolutionChangeEvent (unsigned int width, unsigned int height) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param width The width. * @param height The height. */ MonitorResolutionChangeEvent (unsigned int width, unsigned int height) : m_Width(width), m_Height(height) {} /** * @fn unsigned int MonitorResolutionChangeEvent::GetWidth() const * * @brief Gets the width * * @author <NAME> * @date 10/09/2021 * * @returns The width. */ unsigned int GetWidth() const { return m_Width; } /** * @fn unsigned int MonitorResolutionChangeEvent::GetHeight() const * * @brief Gets the height * * @author <NAME> * @date 10/09/2021 * * @returns The height. */ unsigned int GetHeight() const { return m_Height; } std::string ToString() const override { std::stringstream ss; ss << "MonitorResolutionChangeEvent: " << m_Width << ", " << m_Height; return ss.str(); } EVENT_CLASS_TYPE(MonitorResolutionChange) EVENT_CLASS_CATEGORY(EventCategoryApplication) private: /** @brief The width and height of the window resolution */ unsigned int m_Width, m_Height; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/RenderCommand.h
<reponame>BryceStandley/TNAH #pragma once #include "RendererAPI.h" namespace tnah { /** * @class RenderCommand * * @brief A render command class that makes use of the renderer API to perform openGL renderer actions * * @author <NAME> * @date 12/09/2021 */ class RenderCommand { public: /** * @fn inline static void RenderCommand::Init() * * @brief Initializes this object * * @author <NAME> * @date 12/09/2021 */ inline static void Init() { s_RendererAPI->Init(); } /** * @fn inline static void RenderCommand::SetClearColor(const glm::vec4& color) * * @brief Sets clear color * * @author <NAME> * @date 12/09/2021 * * @param color The color. */ inline static void SetClearColor(const glm::vec4& color) { s_RendererAPI->SetClearColor(color); } /** * @fn inline static void RenderCommand::Clear() * * @brief Clears this object to its blank/initial state * * @author <NAME> * @date 12/09/2021 */ inline static void Clear() { s_RendererAPI->Clear(); } /** * @fn inline static void RenderCommand::DrawArray(const Ref<VertexArray> vertexArray, const DrawMode& mode = DrawMode::Triangles) * * @brief Draws a vertex array * * @author <NAME> * @date 12/09/2021 * * @param vertexArray The vertexArray object used to draw from. * @param mode The DrawMode used to draw the array. Default DrawMode::Triangles * */ inline static void DrawArray(const Ref<VertexArray> vertexArray, const DrawMode& mode = DrawMode::Triangles) { s_RendererAPI->DrawArray(vertexArray, mode); } /** * @fn inline static void RenderCommand::DrawIndexed(const Ref<VertexArray> vertexArray, const DrawMode& mode = DrawMode::Triangles, void* indicesStart = nullptr) * * @brief Draws a vertex array * * @author <NAME> * @date 12/09/2021 * * @param vertexArray The vertexArray object used to draw from. * @param mode The DrawMode used to draw the array. Default DrawMode::Triangles * @param indicesStart The starting point in memory of the indicies. * */ inline static void DrawIndexed(const Ref<VertexArray> vertexArray, const DrawMode& mode = DrawMode::Triangles, void* indicesStart = nullptr) { s_RendererAPI->DrawIndexed(vertexArray, mode, indicesStart); } /** * @fn inline static void RenderCommand::SetViewport(const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height) * * @brief Sets a viewport * * @author <NAME> * @date 12/09/2021 * * @param x An uint32_t to process. * @param y An uint32_t to process. * @param width The width. * @param height The height. */ inline static void SetViewport(const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height) { s_RendererAPI->SetViewport(x, y, width, height); } /** * @fn inline static void RenderCommand::SetWireframe(const bool& enable) * * @brief Sets a wireframe * * @author <NAME> * @date 12/09/2021 * * @param enable True to enable, false to disable. */ inline static void SetWireframe(const bool& enable) { s_RendererAPI->SetWireframe(enable); } /** * @fn inline static bool RenderCommand::CheckFullScreen(const int width, const int height) * * @brief Check full screen * * @author <NAME> * @date 12/09/2021 * * @param width The width. * @param height The height. * * @returns True if it succeeds, false if it fails. */ inline static bool CheckFullScreen(const int width, const int height) { return s_RendererAPI->CheckFullScreen(width, height); } /** * @fn inline static void RenderCommand::SetCullMode(const CullMode& mode) * * @brief Sets cull mode * * @author <NAME> * @date 12/09/2021 * * @param mode The mode. */ inline static void SetCullMode(const CullMode& mode) { s_RendererAPI->SetCullMode(mode); } /** * @fn inline static void RenderCommand::SetDepthMask(const bool& enabled) * * @brief Sets depth mask * * @author <NAME> * @date 12/09/2021 * * @param enabled True to enable, false to disable. */ inline static void SetDepthMask(const bool& enabled) { s_RendererAPI->SetDepthMask(enabled); } /** * @fn inline static void RenderCommand::SetDepthFunc(const DepthFunc& func) * * @brief Sets depth function mode * * @author <NAME> * @date 12/09/2021 * * @param func DepthFunc value to set. */ inline static void SetDepthFunc(const DepthFunc& func) { s_RendererAPI->SetDepthFunc(func); } /** * @fn inline static void RenderCommand::Disable(const APIEnum& value) * * @brief Disables a given API function * * @author <NAME> * @date 12/09/2021 * * @param value APIEnum value to disable. */ inline static void Disable(const APIEnum& value) { s_RendererAPI->Disable(value); } /** * @fn inline static void RenderCommand::Enable(const APIEnum& value) * * @brief Enables a given API function * * @author <NAME> * @date 12/09/2021 * * @param value APIEnum value to enable. */ inline static void Enable(const APIEnum& value) { s_RendererAPI->Enable(value); } private: /** @brief The renderer api */ static RendererAPI* s_RendererAPI; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/Actions.h
/*****************************************************************//** * \file Actions.h * \brief * * \author chris * \date November 2021 *********************************************************************/ #pragma once namespace tnah { /** \enum Actions The actions the objects can afford */ enum Actions { sit = 1, kick = 2, punch = 3, none = 0, greeting = 4, pickup = 5, abuse = 6, sleep = 7, drink = 9, play = 10 }; /** \enum PlayerActions the actions players can do */ enum PlayerActions { pumpUp, calm, compliment, insult }; }
BryceStandley/TNAH
core/src/TNAH/Audio/Audio.h
<filename>core/src/TNAH/Audio/Audio.h #pragma once #include "TNAH/Core/Core.h" #include "TNAH/Scene/Components/AudioComponents.h" #include "Platform/MiniAudio/MiniAudio.h" namespace tnah { /** * @class Audio * * @brief An audio class responisble for handling the audio engine * * @author <NAME> * @date 7/09/2021 */ class Audio { public: /** * @fn static bool Audio::Init(); * * @brief Initializes this object * * @author <NAME> * @date 7/09/2021 * * @returns True if it succeeds, false if it fails. */ static bool Init(); /** * @fn static void Audio::Shutdown(); * * @brief Shuts down this object and frees any resources it is using * * @author <NAME> * @date 7/09/2021 */ static void Shutdown(); /** * @fn static bool Audio::SetListener(TransformComponent &transforms); * * @brief Sets a listener to a given transform component * * @author <NAME> * @date 7/09/2021 * * @param [in,out] transforms The transforms. * * @returns True if it succeeds, false if it fails. */ static bool SetListener(TransformComponent &transforms); /** * @fn static bool Audio::AddAudioSource(AudioSourceComponent &sound); * * @brief Adds an audio source * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * * @returns True if it succeeds, false if it fails. */ static bool AddAudioSource(AudioSourceComponent &sound); /** * @fn static bool Audio::UpdateAudioSource(AudioSourceComponent &sound); * * @brief Updates the audio source described by sound * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * * @returns True if it succeeds, false if it fails. */ static bool UpdateAudioSource(AudioSourceComponent &sound); /** * @fn static void Audio::OnUpdate(); * * @brief Executes the 'update' action * * @author <NAME> * @date 7/09/2021 */ static void OnUpdate(); /** * @fn static void Audio::UpdateSound(AudioSourceComponent& sound, TransformComponent &transforms); * * @brief Updates the sound * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * @param [in,out] transforms The transforms. */ static void UpdateSound(AudioSourceComponent& sound, TransformComponent &transforms); /** * @fn static bool Audio::Active(); * * @brief Activatea this object * * @author <NAME> * @date 7/09/2021 * * @returns True if it succeeds, false if it fails. */ static bool Active(); /** * @fn static void Audio::Clear(); * * @brief Clears this object to its blank/initial state * * @author <NAME> * @date 7/09/2021 */ static void Clear(); private: /** @brief The audio engine */ static AudioAPI * m_AudioEngine; }; };
BryceStandley/TNAH
core/src/TNAH/Layers/Widgets.h
<reponame>BryceStandley/TNAH #pragma once #include "imgui.h" #include "imgui_internal.h" //---------------------------------------------------------------------------------- // Custom Functions added to ImGui // Incorporated by <NAME> // Any functions within this file are licenced under the MIT licence //---------------------------------------------------------------------------------- namespace ImGui { /** * @author Ocornut * @link https://github.com/ocornut */ void ToggleButton(const char* str_id, bool* v); #if 0 /** * @author Zfedorn * @link https://github.com/zfedoran */ static bool BufferingBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col); /** * @author Zfedorn * @link https://github.com/zfedoran */ static bool LineSpinner(const char* label, float radius, int thickness, const ImU32& color); /** * @author Ocornut * @link https://github.com/ocornut */ static void TextSpinner(); /** * @author Alexsr * @link https://github.com/alexsr */ static void DotSpinner(const char* label, const float indicator_radius, const ImVec4& main_color, const ImVec4& backdrop_color, const int circle_count, const float speed); #endif }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/AStar.h
<reponame>BryceStandley/TNAH /*****************************************************************//** * @file AStar.h * @brief Astar algorithm * * @author chris * @date November 2021 *********************************************************************/ #pragma once #include <stack> namespace tnah { /** Int2 struct */ struct Int2 { int x; int y; Int2(int o = 0, int t = 0) : x(o), y(t) {} bool CheckSame(Int2 other) { if(x == other.x && y == other.y) return true; return false; } }; /** Astar obstacle component */ struct AStarObstacleComponent { AStarObstacleComponent() = default; AStarObstacleComponent(bool b) : dynamic(b) {} /** If the object is dynamic or not */ bool dynamic = false; private: inline static std::string s_SearchString = "AStar Obstacle Component"; /** @brief Type identifiers for the component */ inline static ComponentTypes s_Types = { {ComponentVariations::AStarObstacle}, {{ComponentCategory::Objects}} }; friend class EditorUI; }; /** The node for the object */ struct Node { Int2 position; Int2 parent; float f; float g; float h; Node(Int2 p = {0, 0}) : position(p), parent(-1, -1), f(-1), g(-1), h(-1) {} }; inline bool operator < (const Node& left, const Node & right) { return left.f < right.f; } class AStar { public: AStar() {} ~AStar() = default; /** * * @fn IsValid * @brief Checks if the given point is valid * * @param point * @return bool * @author chris */ static bool IsValid(Int2 point); /** * * @fn Update * @brief Updates the dynamic positions * * @author chris */ static void Update(); /** * * @fn Reached * @brief Checks if the position is reached * * @param point * @param destination * @return * @author chris */ static bool Reached(Int2 point, Node destination); /** * * @fn heuristic * @brief Gets the H value using square root * * @param point * @param destination * @return * @author chris */ static double heuristic(Int2 point, Node destination); /** * * @fn Init * @brief Initilises the astar map * * @param startingPosition * @param xySize * @author chris */ static void Init(Int2 startingPosition, Int2 xySize); /** * * @fn Algorithm * @brief DOes the algorithm calling make path * * @param point * @param destination * @return * @author chris */ static std::deque<Node> Algorithm(Node point, Node destination); /** * * @fn GenerateRandomPosition * @brief Generates a random position on the map * * @param currentPosition * @return * @author chris */ static Node GenerateRandomPosition(Int2 currentPosition); /** * * @fn GetMapPoints * @brief Gets the map points * * @return * @author chris */ static std::unordered_map<int, std::unordered_map<int, Node>> GetMapPoints(); /** * * @fn GetUsedPoints * @brief Gets the map points taht are obstacles * * @return * @author chris */ static std::unordered_map<int, std::unordered_map<int, bool>> GetUsedPoints(); /** * * @fn AddUsedPosition * @brief Adds the given position to the used map, and adds it to the dynamic one if dynamic * * @param position * @param dynamic * @author chris */ static void AddUsedPosition(Int2 position, bool dynamic); /** * * @fn GetStartingPos * @brief Gets the starting position * * @return * @author chris */ static Int2 GetStartingPos(); /** * * @fn GetEndPosition * @brief Gets the end position * * @return * @author chris */ static Int2 GetEndPosition(); private: /** * * @fn makePath * @brief Creates the path used in the algorithm * * @param map * @param destination * @return * @author chris */ static std::deque<Node> makePath(std::unordered_map<int, std::unordered_map<int, Node>> map, Node destination); /** If it is initilised*/ inline static bool initilised = false; /** The starting position*/ inline static Int2 startingPos = {0, 0}; /** The overall size */ inline static Int2 size = {10, 10}; /** If it has been generated */ inline static bool generated = false; /** The map holding the closed list*/ inline static std::unordered_map<int, std::unordered_map<int, bool>> closedList = std::unordered_map<int, std::unordered_map<int, bool>>(); /** The map holding the used position*/ inline static std::unordered_map<int, std::unordered_map<int, bool>> usedPositions = std::unordered_map<int, std::unordered_map<int, bool>>(); /** The map holding the overall map */ inline static std::unordered_map<int, std::unordered_map<int, Node>> astarMap = std::unordered_map<int, std::unordered_map<int, Node>>(); /** The vector holding the dynamic positions*/ inline static std::vector<Int2> usedPositionsHolder = std::vector<Int2>(); }; struct AStarComponent { AStarComponent() = default; AStarComponent(Int2 pos, Int2 s) : StartingPos(pos), Size(s) {} AStarComponent(const AStarComponent &copy) { StartingPos = copy.StartingPos; Size = copy.Size; } /** */ Int2 StartingPos = {0, 0}; /** */ Int2 Size = {5, 5}; /** */ bool DisplayMap = false; /** */ bool reset = true; private: inline static std::string s_SearchString = "AStar Component"; /** @brief Type identifiers for the component */ inline static ComponentTypes s_Types = { {ComponentVariations::AStar}, {{ComponentCategory::Objects}} }; friend class EditorUI; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Renderer.h
#pragma once #include "TNAH/Renderer/RenderCommand.h" #include "TNAH/Scene/SceneCamera.h" #include "TNAH/Scene/Components/Components.h" #include "TNAH/Renderer/Material.h" #include "Light.h" #include "Mesh.h" #include "Texture.h" namespace tnah { /** * @class Renderer * * @brief A renderer class responsible for the rendering of things such as meshes, terrain and skyboxes * * @author <NAME> * @date 12/09/2021 */ class Renderer { public: /** * @fn static void Renderer::Init(); * * @brief Initializes this object * * @author <NAME> * @date 12/09/2021 */ static void Init(); /** * @fn static void Renderer::Shutdown(); * * @brief Shuts down this object and frees any resources it is using * * @author <NAME> * @date 12/09/2021 */ static void Shutdown(); /** * @fn static void Renderer::OnWindowResize(uint32_t width, uint32_t height); * * @brief Executes when the window is resized * * @author <NAME> * @date 12/09/2021 * * @param width The width. * @param height The height. */ static void OnWindowResize(uint32_t width, uint32_t height); /** * @fn static void Renderer::BeginScene(SceneCamera& camera); * * @brief Begins a scene * * @author <NAME> * @date 12/09/2021 * * @param [in,out] camera The camera. */ static void BeginScene(SceneCamera& camera); /** * @fn static void Renderer::BeginScene(SceneCamera& camera, TransformComponent& cameraTransform); * * @brief Begins a scene * * @author <NAME> * @date 12/09/2021 * * @param [in,out] camera The camera. * @param [in,out] cameraTransform The camera transform. */ static void BeginScene(SceneCamera& camera, TransformComponent& cameraTransform); /** * @fn static void Renderer::EndScene(); * * @brief Ends a scene * * @author <NAME> * @date 12/09/2021 */ static void EndScene(); /** * @fn static void Renderer::IncrementTextureSlot() * * @brief Increment texture slot * * @author <NAME> * @date 12/09/2021 */ static void IncrementTextureSlot() { s_CurrentTextureSlot++; } /** * @fn static uint32_t Renderer::GetCurrentTextureSlot() * * @brief Gets current texture slot * * @author <NAME> * @date 12/09/2021 * * @returns The current texture slot. */ static uint32_t GetCurrentTextureSlot() { return s_CurrentTextureSlot; } /** * @fn static uint32_t Renderer::GetAndIncrementTextureSlot() * * @brief Gets and increment texture slot * * @author <NAME> * @date 12/09/2021 * * @returns The and increment texture slot. */ static uint32_t GetAndIncrementTextureSlot() { s_CurrentTextureSlot++; return s_CurrentTextureSlot - 1; } /** * @fn static void Renderer::SetCullMode(const CullMode& mode); * * @brief Sets cull mode * * @author <NAME> * @date 12/09/2021 * * @param mode The mode. */ static void SetCullMode(const CullMode& mode); /** * @fn static void Renderer::SetShaderLightInfo(Ref<Material> material, std::vector<Ref<Light>> lights); * * @brief Sets shader light information * * @author <NAME> * @date 12/09/2021 * * @param material The material. * @param lights The lights. */ static void SetShaderLightInfo(Ref<Material> material, std::vector<Ref<Light>> lights); /** * @fn static void Renderer::Submit(Ref<VertexArray> vertexArray, Ref<Shader> shader, const glm::mat4& transform = glm::mat4(1.0f)); * * @brief Submits to the renderer * * @author <NAME> * @date 12/09/2021 * * @param vertexArray Array of vertices. * @param shader The shader. * @param transform (Optional) The transform. */ static void Submit(Ref<VertexArray> vertexArray, Ref<Shader> shader, const glm::mat4& transform = glm::mat4(1.0f)); /** * @fn static void Renderer::SubmitTerrain(Ref<VertexArray> vertexArray, Ref<Material> material, std::vector<Ref<Light>> sceneLights, const glm::mat4& transform = glm::mat4(1.0f)); * * @brief Submit terrain * * @author <NAME> * @date 12/09/2021 * * @param vertexArray Array of vertices. * @param material The material. * @param sceneLights The scene lights. * @param transform (Optional) The transform. */ static void SubmitTerrain(Ref<VertexArray> vertexArray, Ref<Material> material, std::vector<Ref<Light>> sceneLights, const glm::mat4& transform = glm::mat4(1.0f)); /** * @fn static void Renderer::SubmitMesh(Ref<VertexArray> vertexArray, Ref<Material> material, std::vector<Ref<Light>> sceneLights, const glm::mat4& transform = glm::mat4(1.0f), const bool& isAnimated = false, const std::vector<glm::mat4>& animTransforms = {glm::mat4(1.0f)}); * * @brief Submit mesh * * @author <NAME> * @date 12/09/2021 * * @param vertexArray Array of vertices. * @param material The material. * @param sceneLights The scene lights. * @param transform (Optional) The transform. * @param isAnimated (Optional) True if is animated, false if not. * @param animTransforms (Optional) The animation transforms. */ static void SubmitMesh(Ref<VertexArray> vertexArray, Ref<Material> material, std::vector<Ref<Light>> sceneLights, const glm::mat4& transform = glm::mat4(1.0f), const bool& isAnimated = false, const std::vector<glm::mat4>& animTransforms = {glm::mat4(1.0f)}); /** * @fn static void Renderer::SubmitSkybox(Ref<VertexArray> vertexArray, Ref<SkyboxMaterial> material); * * @brief Submit skybox * * @author <NAME> * @date 12/09/2021 * * @param vertexArray Array of vertices. * @param material The material. */ static void SubmitSkybox(Ref<VertexArray> vertexArray, Ref<SkyboxMaterial> material); /** * @fn static void Renderer::SubmitCollider(Ref<VertexArray> lineVertexArray, Ref<VertexBuffer> lineVertexBuffer, Ref<VertexArray> triangleVertexArray, Ref<VertexBuffer> triangleVertexBuffer); * * @brief Submit collider * * @author <NAME> * @date 12/09/2021 * * @param lineVertexArray Array of vertices. * @param lineVertexBuffer Buffer for line vertex data. * @param triangleVertexArray Array of vertices. * @param triangleVertexBuffer Buffer for triangle vertex data. */ static void SubmitCollider(Ref<VertexArray> lineVertexArray, Ref<VertexBuffer> lineVertexBuffer, Ref<VertexArray> triangleVertexArray, Ref<VertexBuffer> triangleVertexBuffer); /** * @fn static RendererAPI::API Renderer::GetAPI() * * @brief Gets the renderer API * * @author <NAME> * @date 12/09/2021 * * @returns the renderer API. */ static RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); } /** * @fn static Ref<Texture2D> Renderer::GetWhiteTexture(); * * @brief Gets white texture * * @author <NAME> * @date 12/09/2021 * * @returns The white texture. */ static Ref<Texture2D> GetWhiteTexture(); /** * @fn static Ref<Texture2D> Renderer::GetBlackTexture(); * * @brief Gets black texture * * @author <NAME> * @date 12/09/2021 * * @returns The black texture. */ static Ref<Texture2D> GetBlackTexture(); /** * @fn static Ref<Texture2D> Renderer::GetMissingTexture(); * * @brief Gets missing texture * * @author <NAME> * @date 12/09/2021 * * @returns The missing texture. */ static Ref<Texture2D> GetMissingTexture(); /** * @fn static std::vector<Ref<Texture2D>> Renderer::GetLoadedTextures(); * * @brief Gets loaded textures * * @author <NAME> * @date 12/09/2021 * * @returns The loaded textures. */ static std::vector<Ref<Texture2D>> GetLoadedTextures(); /** * @fn static std::vector<Ref<Shader>> Renderer::GetLoadedShaders(); * * @brief Gets loaded shaders * * @author <NAME> * @date 12/09/2021 * * @returns The loaded shaders. */ static std::vector<Ref<Shader>> GetLoadedShaders(); /** * @fn static void Renderer::RegisterTexture(Ref<Texture2D> texture); * * @brief Registers the texture described by texture * * @author <NAME> * @date 12/09/2021 * * @param texture The texture. */ static void RegisterTexture(Ref<Texture2D> texture); /** * @fn static void Renderer::RegisterShader(Ref<Shader> shader); * * @brief Registers the shader described by shader * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. */ static void RegisterShader(Ref<Shader> shader); /** * @fn static std::vector<Ref<Model>> Renderer::GetLoadedModels(); * * @brief Gets loaded models * * @author <NAME> * @date 12/09/2021 * * @returns The loaded models. */ static std::vector<Ref<Model>> GetLoadedModels(); /** * @fn static void Renderer::RegisterModel(Ref<Model> model); * * @brief Registers the model described by model * * @author <NAME> * @date 12/09/2021 * * @param model The model. */ static void RegisterModel(Ref<Model> model); /** * @fn static uint32_t Renderer::GetDrawCallsPerFrame(); * * @brief Gets draw calls per frame * * @author <NAME> * @date 12/09/2021 * * @returns The draw calls per frame. */ static uint32_t GetDrawCallsPerFrame(); /** * @fn static uint32_t Renderer::GetTotalLoadedTextures(); * * @brief Gets total loaded textures * * @author <NAME> * @date 12/09/2021 * * @returns The total loaded textures. */ static uint32_t GetTotalLoadedTextures(); /** * @fn static uint32_t Renderer::GetTotalLoadedShaders(); * * @brief Gets total loaded shaders * * @author <NAME> * @date 12/09/2021 * * @returns The total loaded shaders. */ static uint32_t GetTotalLoadedShaders(); /** * @fn static uint32_t Renderer::GetTotalLoadedModels(); * * @brief Gets total loaded models * * @author <NAME> * @date 12/09/2021 * * @returns The total loaded models. */ static uint32_t GetTotalLoadedModels(); private: /** * @fn static void Renderer::IncrementDrawCallsPerFrame(); * * @brief Increment draw calls per frame * * @author <NAME> * @date 12/09/2021 */ static void IncrementDrawCallsPerFrame(); /** * @fn static void Renderer::IncrementTotalLoadedTextures(); * * @brief Increment total loaded textures * * @author <NAME> * @date 12/09/2021 */ static void IncrementTotalLoadedTextures(); /** * @fn static void Renderer::IncrementTotalLoadedShaders(); * * @brief Increment total loaded shaders * * @author <NAME> * @date 12/09/2021 */ static void IncrementTotalLoadedShaders(); /** * @fn static void Renderer::IncrementTotalLoadedModels(); * * @brief Increment total loaded models * * @author <NAME> * @date 12/09/2021 */ static void IncrementTotalLoadedModels(); /** * @fn static void Renderer::ResetDrawCallsPerFrame(); * * @brief Resets the draw calls per frame * * @author <NAME> * @date 12/09/2021 */ static void ResetDrawCallsPerFrame(); /** * @fn static void Renderer::ResetTotalLoadedTextures(); * * @brief Resets the total loaded textures * * @author <NAME> * @date 12/09/2021 */ static void ResetTotalLoadedTextures(); /** * @fn static void Renderer::ResetTotalLoadedShaders(); * * @brief Resets the total loaded shaders * * @author <NAME> * @date 12/09/2021 */ static void ResetTotalLoadedShaders(); /** * @fn static void Renderer::ResetTotalLoadedModels(); * * @brief Resets the total loaded models * * @author <NAME> * @date 12/09/2021 */ static void ResetTotalLoadedModels(); /** * @struct SceneData * * @brief scene data. * * @author <NAME> * @date 12/09/2021 */ struct SceneData { /** @brief The view */ glm::mat4 View; /** @brief The projection */ glm::mat4 Projection; /** @brief The view projection */ glm::mat4 ViewProjection; /** @brief The camera transform */ TransformComponent CameraTransform; }; /** @brief The current texture slot */ static uint32_t s_CurrentTextureSlot; /** @brief Information describing the scene */ static SceneData* s_SceneData; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/RenderingBuffers.h
<filename>core/src/TNAH/Renderer/RenderingBuffers.h #pragma once #include <glm/glm.hpp> #include <glm/gtc/type_ptr.hpp> #include "TNAH/Core/Ref.h" namespace tnah { /** * @enum ShaderDataType * * @brief Values that represent shader data types */ enum class ShaderDataType { None = 0, Float, Float2, Float3, Float4, Mat3, Mat4, Int, Int2, Int3, Int4, Bool, UInt }; /** * @fn static uint32_t ShaderDataTypeSize(ShaderDataType type) * * @brief Shader data type size * * @author <NAME> * @date 12/09/2021 * * @param type The type. * * @returns An uint32_t. */ static uint32_t ShaderDataTypeSize(ShaderDataType type) { switch (type) { case ShaderDataType::Float: return 4; case ShaderDataType::Float2: return 4 * 2; case ShaderDataType::Float3: return 4 * 3; case ShaderDataType::Float4: return 4 * 4; case ShaderDataType::Mat3: return 4 * 3 * 3; case ShaderDataType::Mat4: return 4 * 4 * 4; case ShaderDataType::UInt: return 4; case ShaderDataType::Int: return 4; case ShaderDataType::Int2: return 4 * 2; case ShaderDataType::Int3: return 4 * 3; case ShaderDataType::Int4: return 4 * 4; case ShaderDataType::Bool: return 1; case ShaderDataType::None: break; default: break; } TNAH_CORE_ASSERT(false, "Unknown ShaderDataType!"); return 0; } /** * @struct BufferElement * * @brief A buffer element. * * @author <NAME> * @date 12/09/2021 */ struct BufferElement { /** @brief The name */ std::string Name; /** @brief The type */ ShaderDataType Type; /** @brief The size */ uint32_t Size; /** @brief The offset */ size_t Offset; /** @brief True if normalized */ bool Normalized; /** * @fn BufferElement() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ BufferElement() = default; /** * @fn BufferElement(ShaderDataType type, const std::string& name, bool normalized = false) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param type The type. * @param name The name. * @param normalized (Optional) True if normalized. */ BufferElement(ShaderDataType type, const std::string& name, bool normalized = false) : Name(name), Type(type), Size(ShaderDataTypeSize(type)), Offset(0), Normalized(normalized) { } /** * @fn uint32_t GetComponentCount() const * * @brief Gets component count * * @author <NAME> * @date 12/09/2021 * * @returns The component count. */ uint32_t GetComponentCount() const { switch (Type) { case ShaderDataType::Float: return 1; case ShaderDataType::Float2: return 2; case ShaderDataType::Float3: return 3; case ShaderDataType::Float4: return 4; case ShaderDataType::Mat3: return 3; // 3* float3 case ShaderDataType::Mat4: return 4; // 4* float4 case ShaderDataType::UInt: return 3; case ShaderDataType::Int: return 1; case ShaderDataType::Int2: return 2; case ShaderDataType::Int3: return 3; case ShaderDataType::Int4: return 4; case ShaderDataType::Bool: return 1; default: break; } TNAH_CORE_ASSERT(false, "Unknown ShaderDataType!"); return 0; } }; /** * @class VertexBufferLayout * * @brief A buffer layout class responsible for handling the contents of a buffer * * @author <NAME> * @date 12/09/2021 */ class VertexBufferLayout { public: /** * @fn VertexBufferLayout::VertexBufferLayout() * * @brief Default constructor * * @author <NAME> * @date 12/09/2021 */ VertexBufferLayout() {} /** * @fn VertexBufferLayout::VertexBufferLayout(std::initializer_list<BufferElement> elements) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param elements The elements. */ VertexBufferLayout(std::initializer_list<BufferElement> elements) : m_Elements(elements) { CalculateOffsetsAndStride(m_Elements, m_Stride); } /** * @fn uint32_t VertexBufferLayout::GetStride() const * * @brief Gets the stride * * @author <NAME> * @date 12/09/2021 * * @returns The stride. */ uint32_t GetStride() const { return m_Stride; } /** * @fn const std::vector<BufferElement>& VertexBufferLayout::GetElements() const * * @brief Gets the elements * * @author <NAME> * @date 12/09/2021 * * @returns The elements. */ const std::vector<BufferElement>& GetElements() const { return m_Elements; } /** * @fn std::vector<BufferElement>::iterator VertexBufferLayout::begin() * * @brief Gets an iterator from the begin point of a vector * * @author <NAME> * @date 12/09/2021 * * @returns A std::vector<BufferElement>::iterator. */ std::vector<BufferElement>& GetElements() { return m_Elements; } void SetStride(const uint32_t& stride) { m_Stride = stride; } std::vector<BufferElement>::iterator begin() { return m_Elements.begin(); } /** * @fn std::vector<BufferElement>::iterator VertexBufferLayout::end() * * @brief Gets an iterator from the end point of a vector * * @author <NAME> * @date 12/09/2021 * * @returns A std::vector<BufferElement>::iterator. */ std::vector<BufferElement>::iterator end() { return m_Elements.end(); } /** * @fn std::vector<BufferElement>::const_iterator VertexBufferLayout::begin() const * * @brief Gets a const iterator from the begin point of a vector * * @author <NAME> * @date 12/09/2021 * * @returns A std::vector<BufferElement>::const_iterator. */ std::vector<BufferElement>::const_iterator begin() const { return m_Elements.begin(); } /** * @fn std::vector<BufferElement>::const_iterator VertexBufferLayout::end() const * * @brief Gets a const iterator from the end point of a vector * * @author <NAME> * @date 12/09/2021 * * @returns A std::vector&lt;BufferElement&gt;::const_iterator. */ std::vector<BufferElement>::const_iterator end() const { return m_Elements.end(); } private: /** * @fn static void VertexBufferLayout::CalculateOffsetsAndStride(std::vector<BufferElement>& elements, uint32_t& stride) * * @brief Calculates the offsets and stride * * @author <NAME> * @date 12/09/2021 * * @param [in,out] elements The elements. * @param [in,out] stride The stride. */ static void CalculateOffsetsAndStride(std::vector<BufferElement>& elements, uint32_t& stride) { size_t offset = 0; stride = 0; for (auto& element : elements) { element.Offset = offset; offset += element.Size; stride += element.Size; } } private: /** @brief The elements */ std::vector<BufferElement> m_Elements; /** @brief The stride */ uint32_t m_Stride = 0; friend class VertexBuffer; }; /** * @enum DrawType * * @brief Values that represent draw types */ enum class DrawType { STREAM, STATIC, DYNAMIC }; /** * @enum TypeMode * * @brief Values that represent type modes */ enum class TypeMode { DRAW, READ, COPY }; /** * @struct BufferDrawMode * * @brief A draw mode. * * @author <NAME> * @date 12/09/2021 */ struct BufferDrawMode { DrawType Type = DrawType::STATIC; TypeMode Mode = TypeMode::DRAW; }; /** * @class VertexBuffer * * @brief VertexBuffer class that abstracts the opengl calls required to use a vbo * * @author <NAME> * @date 12/09/2021 */ class VertexBuffer : public RefCounted { public: /** * @fn virtual VertexBuffer::~VertexBuffer() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~VertexBuffer() = default; /** * @fn virtual void VertexBuffer::Bind() const = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() const = 0; /** * @fn virtual void VertexBuffer::Unbind() const = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() const = 0; /** * @fn virtual void VertexBuffer::SetData(uint32_t size, const void* data, DrawType type = DrawType::STATIC, TypeMode mode = TypeMode::DRAW) const = 0; * * @brief Sets data * * @author <NAME> * @date 12/09/2021 * * @param size The size. * @param data The data. * @param type (Optional) The draw type. * @param mode (Optional) The type mode. */ virtual void SetData(uint32_t size, const void* data, DrawType type = DrawType::STATIC, TypeMode mode = TypeMode::DRAW) const = 0; /** * @fn virtual void VertexBuffer::CreateLayout(uint32_t location, BufferElement element, uint32_t stride) = 0; * * @brief Creates a layout * * @author <NAME> * @date 12/09/2021 * * @param location The location. * @param element The element. * @param stride The stride. */ virtual void CreateLayout(uint32_t location, BufferElement element, uint32_t stride) = 0; /** * @fn virtual void VertexBuffer::DisableLayout(uint32_t location) = 0; * * @brief Disables the layout * * @author <NAME> * @date 12/09/2021 * * @param location The location. */ virtual void DisableLayout(uint32_t location) = 0; /** * @fn virtual const VertexBufferLayout& VertexBuffer::GetLayout() const = 0; * * @brief Gets the layout * * @author <NAME> * @date 12/09/2021 * * @returns The layout. */ virtual const VertexBufferLayout& GetLayout() const = 0; /** * @fn virtual void VertexBuffer::SetLayout(const VertexBufferLayout& layout) = 0; * * @brief Sets a layout * * @author <NAME> * @date 12/09/2021 * * @param layout The layout. */ virtual void SetLayout(const VertexBufferLayout& layout) = 0; /** * @fn static Ref<VertexBuffer> VertexBuffer::Create(); * * @brief Creates a new VertexBuffer * * @author <NAME> * @date 12/09/2021 * * @returns A VertexBuffer */ static Ref<VertexBuffer> Create(); static bool CheckIntShaderDataTypes(const BufferElement& element); /** * @fn static Ref<VertexBuffer> VertexBuffer::Create(float* verticies, uint32_t size); * * @brief Creates a new VertexBuffer * * @author <NAME> * @date 12/09/2021 * * @param [in,out] verticies If non-null, the verticies. * @param size The size. * * @returns A VertexBuffer */ static Ref<VertexBuffer> Create(float* verticies, uint32_t size); /** * @fn static Ref<VertexBuffer> VertexBuffer::Create(void* verticies, uint32_t size); * * @brief Creates a new VertexBuffer * * @author <NAME> * @date 12/09/2021 * * @param [in,out] verticies If non-null, the verticies. * @param size The size. * * @returns A VertexBuffer */ static Ref<VertexBuffer> Create(void* verticies, uint32_t size); }; /** * @class IndexBuffer * * @brief Class that allows for the creation of Index Buffers (IBO) * * @author <NAME> * @date 12/09/2021 */ enum class IndexBufferDataType { Byte = 0, Short = 1, Int = 2 }; // Currently tnah only supports 32-bit index buffers class IndexBuffer : public RefCounted { public: /** * @fn virtual IndexBuffer::~IndexBuffer() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~IndexBuffer() = default; /** * @fn virtual void IndexBuffer::Bind() const = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() const = 0; /** * @fn virtual void IndexBuffer::Unbind() const = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() const = 0; /** * @fn virtual uint32_t IndexBuffer::GetCount() const = 0; * * @brief Gets the count * * @author <NAME> * @date 12/09/2021 * * @returns The count. */ virtual uint32_t GetCount() const = 0; virtual int GetDataType() const = 0; /** * @fn static Ref<IndexBuffer> IndexBuffer::Create(uint32_t* indices, uint32_t size); * * @brief Creates a new IndexBuffer * * @author <NAME> * @date 12/09/2021 * * @param [in,out] indices If non-null, the indices. * @param size The size. * * @returns An IndexBuffer */ static Ref<IndexBuffer> Create(uint32_t* indices, uint32_t size); /** * @fn static Ref<IndexBuffer> IndexBuffer::Create(void* indices, uint32_t size); * * @brief Creates a new IndexBuffer * * @author <NAME> * @date 12/09/2021 * * @param [in,out] indices If non-null, the indices. * @param size The size. * * @returns An IndexBuffer */ static Ref<IndexBuffer> Create(void* indices, uint32_t size); /** * @fn static Ref<IndexBuffer> IndexBuffer::Create(uint32_t size); * * @brief Creates an empty index buffer with a size. * * @author <NAME> * @date 12/09/2021 * * @param size The size. * * @returns An IndexBuffer */ static Ref<IndexBuffer> Create(uint32_t size); }; /** * @enum RenderbufferFormat * * @brief Values that represent renderbuffer formats */ enum class RenderbufferFormat { Depth16, Depth24, Depth32F, Depth24_Stencil8, Depth32F_Stencil8, Stencil8 }; /** * @struct RenderbufferSpecification * * @brief A renderbuffer specification. * * @author <NAME> * @date 12/09/2021 */ struct RenderbufferSpecification { /** @brief The width */ uint32_t Width = 0; /** @brief The height */ uint32_t Height = 0; /** @brief Describes the format to use */ RenderbufferFormat Format = RenderbufferFormat::Depth24_Stencil8; /** @brief The samples */ uint32_t Samples = 1; /** @brief True to swap chain target */ bool SwapChainTarget = false; /** @brief True if is valid, false if not */ bool IsValid = true; /** * @fn RenderbufferSpecification() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ RenderbufferSpecification() = default; /** * @fn RenderbufferSpecification(uint32_t valid) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param valid The valid. */ RenderbufferSpecification(uint32_t valid) :IsValid(false) {} }; /** * @enum FramebufferFormat * * @brief Values that represent framebuffer formats */ enum class FramebufferFormat { SDR, HDR }; /** * @struct FramebufferSpecification * * @brief A framebuffer specification. * * @author <NAME> * @date 12/09/2021 */ struct FramebufferSpecification { /** @brief The width */ uint32_t Width = 0; /** @brief The height */ uint32_t Height = 0; /** @brief Describes the format to use */ FramebufferFormat Format = FramebufferFormat::SDR; /** @brief The samples */ uint32_t Samples = 1; /** @brief True to swap chain target */ bool SwapChainTarget = false; }; struct ColorAttachmentSpecs { /** @brief The width */ uint32_t Width = 0; /** @brief The height */ uint32_t Height = 0; /** @brief Describes the format to use */ FramebufferFormat Format = FramebufferFormat::SDR; }; /** * @enum FramebufferDrawMode * * @brief Values that represent framebuffer draw modes */ enum class FramebufferDrawMode { Depth, Color, Stencil, Render }; /** * @class Framebuffer * * @brief A framebuffer class * * @author <NAME> * @date 12/09/2021 */ class Framebuffer : public RefCounted { public: /** * @fn virtual Framebuffer::~Framebuffer() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Framebuffer() = default; /** * @fn virtual const FramebufferSpecification& Framebuffer::GetSpecification() const = 0; * * @brief Gets the specification * * @author <NAME> * @date 12/09/2021 * * @returns The specification. */ virtual const FramebufferSpecification& GetSpecification() const = 0; /** * @fn virtual void Framebuffer::DrawToNext() = 0; * * @brief Draw to next * * @author <NAME> * @date 12/09/2021 */ virtual void DrawToNext() = 0; /** * @fn virtual uint32_t Framebuffer::GetColorAttachment() const = 0; * * @brief Gets color attachment * * @author <NAME> * @date 12/09/2021 * * @returns The color attachment. */ virtual uint32_t GetColorAttachment() const = 0; /** * @fn virtual uint32_t Framebuffer::GetColorAttachment(uint32_t attachmentNumber) const = 0; * * @brief Gets color attachment * * @author <NAME> * @date 12/09/2021 * * @param attachmentNumber The attachment number. * * @returns The color attachment. */ virtual uint32_t GetColorAttachment(uint32_t attachmentNumber) const = 0; /** * @fn virtual uint32_t Framebuffer::GetTotalColorAttachments() const = 0; * * @brief Gets total color attachments * * @author <NAME> * @date 12/09/2021 * * @returns The total color attachments. */ virtual uint32_t GetTotalColorAttachments() const = 0; /** * @fn virtual uint32_t Framebuffer::GetDepthAttachmentID() const = 0; * * @brief Gets depth attachment identifier * * @author <NAME> * @date 12/09/2021 * * @returns The depth attachment identifier. */ virtual uint32_t GetDepthAttachmentID() const = 0; /** * @fn virtual uint32_t Framebuffer::GetDepthAttachmentID(uint32_t attachmentNumber) const = 0; * * @brief Gets depth attachment identifier * * @author <NAME> * @date 12/09/2021 * * @param attachmentNumber The attachment number. * * @returns The depth attachment identifier. */ virtual uint32_t GetDepthAttachmentID(uint32_t attachmentNumber) const = 0; /** * @fn virtual uint32_t Framebuffer::GetTotalDepthAttachments() const = 0; * * @brief Gets total depth attachments * * @author <NAME> * @date 12/09/2021 * * @returns The total depth attachments. */ virtual uint32_t GetTotalDepthAttachments() const = 0; /** * @fn virtual uint32_t Framebuffer::GetRenderBufferID() const = 0; * * @brief Gets render buffer identifier * * @author <NAME> * @date 12/09/2021 * * @returns The render buffer identifier. */ virtual uint32_t GetRenderBufferID() const = 0; /** * @fn virtual void Framebuffer::SetRenderbufferSpecification(uint32_t bufferSlot, const RenderbufferSpecification& spec) = 0; * * @brief Sets renderbuffer specification * * @author <NAME> * @date 12/09/2021 * * @param bufferSlot The buffer slot. * @param spec The specifier. */ virtual void SetRenderbufferSpecification(uint32_t bufferSlot, const RenderbufferSpecification& spec) = 0; /** * @fn virtual uint32_t Framebuffer::GetRendererID() const = 0; * * @brief Gets renderer identifier * * @author <NAME> * @date 12/09/2021 * * @returns The renderer identifier. */ virtual uint32_t GetRendererID() const = 0; /** * @fn virtual void Framebuffer::Bind(uint32_t attachmentSlot = 0) = 0; * * @brief Binds the given attachment slot * * @author <NAME> * @date 12/09/2021 * * @param attachmentSlot (Optional) The attachment slot. */ virtual void Bind(uint32_t attachmentSlot = 0) = 0; /** * @fn virtual void Framebuffer::Unbind() = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() = 0; /** * @fn virtual void Framebuffer::Rebuild(const FramebufferSpecification& spec) = 0; * * @brief Rebuilds the given specifier * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. */ virtual void Rebuild(const FramebufferSpecification& spec) = 0; /** * @fn static Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& spec, uint32_t colorAttachments = 1, uint32_t depthAttachments = 1); * * @brief Creates a new FrameBuffer * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * @param colorAttachments (Optional) The color attachments. * @param depthAttachments (Optional) The depth attachments. * * @returns A FrameBuffer */ static Ref<Framebuffer> Create(const FramebufferSpecification& spec, uint32_t colorAttachments = 1, uint32_t depthAttachments = 1); /** * @fn static Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& spec, uint32_t colorAttachments, std::vector<ColorAttachmentSpecs> colorSpecs); * * @brief Creates a new FrameBuffer * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * @param colorAttachments The color attachments. * @param colorSpecs The color specs. * * @returns A FrameBuffer */ static Ref<Framebuffer> Create(const FramebufferSpecification& spec, uint32_t colorAttachments, std::vector<ColorAttachmentSpecs> colorSpecs); /** * @fn static Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& spec, const RenderbufferSpecification& renderSpec); * * @brief Creates a new FrameBuffer * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * @param renderSpec Information describing the render. * * @returns A FrameBuffer */ static Ref<Framebuffer> Create(const FramebufferSpecification& spec, const RenderbufferSpecification& renderSpec); /** * @fn virtual void Framebuffer::SelectDrawToBuffer(const FramebufferDrawMode& mode = FramebufferDrawMode::Color, uint32_t attachmentNumber = 0) = 0; * * @brief Select draw to buffer * * @author <NAME> * @date 12/09/2021 * * @param mode (Optional) The mode. * @param attachmentNumber (Optional) The attachment number. */ virtual void SelectDrawToBuffer(const FramebufferDrawMode& mode = FramebufferDrawMode::Color, uint32_t attachmentNumber = 0) = 0; /** * @fn virtual int Framebuffer::GetFormatFromSpec(const FramebufferSpecification& spec) = 0; * * @brief Gets format from specifier * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * * @returns The format from specifier. */ virtual int GetFormatFromSpec(const FramebufferSpecification& spec) = 0; }; /** * @class Renderbuffer * * @brief A renderbuffer class. Inherits from RefCounted to allow the class to use Ref pointer * * @author <NAME> * @date 12/09/2021 */ class Renderbuffer : public RefCounted { public: /** * @fn virtual Renderbuffer::~Renderbuffer() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Renderbuffer() = default; /** * @fn virtual uint32_t Renderbuffer::GetRendererID() const = 0; * * @brief Gets renderer identifier * * @author <NAME> * @date 12/09/2021 * * @returns The renderer identifier. */ virtual uint32_t GetRendererID() const = 0; /** * @fn virtual void Renderbuffer::Bind() = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() = 0; /** * @fn virtual void Renderbuffer::Unbind() = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() = 0; /** * @fn virtual void Renderbuffer::Rebuild(const RenderbufferSpecification& spec) = 0; * * @brief Rebuilds the given specifier * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. */ virtual void Rebuild(const RenderbufferSpecification& spec) = 0; /** * @fn virtual void Renderbuffer::AttachToFramebuffer() = 0; * * @brief Attach to framebuffer * * @author <NAME> * @date 12/09/2021 */ virtual void AttachToFramebuffer() = 0; /** * @fn static Ref<Renderbuffer> Renderbuffer::Create(const RenderbufferSpecification& spec); * * @brief Creates a new RenderBuffer * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * * @returns A RenderBuffer */ static Ref<Renderbuffer> Create(const RenderbufferSpecification& spec); /** * @fn virtual int Renderbuffer::GetFormatFromSpecification(const RenderbufferSpecification& spec) = 0; * * @brief Gets format from specification * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * * @returns The format from specification. */ virtual int GetFormatFromSpecification(const RenderbufferSpecification& spec) = 0; /** * @fn virtual int Renderbuffer::GetFramebufferFormatFromSpecification(const RenderbufferSpecification& spec) = 0; * * @brief Gets framebuffer format from specification * * @author <NAME> * @date 12/09/2021 * * @param spec The specifier. * * @returns The framebuffer format from specification. */ virtual int GetFramebufferFormatFromSpecification(const RenderbufferSpecification& spec) = 0; private: friend class Framebuffer; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/EmotionComponent.h
<filename>core/src/TNAH/Scene/Components/AI/EmotionComponent.h #pragma once #include "Emotion.h" namespace tnah { /** * @class EmotionComponent * * @brief The EmotionComponent class repsonsible for the managing of emotions, mood and personality. Can be attached as a component to give a gameobject the ability to have Emotions * * @author <NAME> * @date 3/11/2021 */ class EmotionComponent { public: /** * @fn EmotionComponent * * @brief Default Constructor * * @author <NAME> * @date 3/11/2021 * */ EmotionComponent(); /** * @fn EmotionComponent * * @brief Constructor that takes valence, arousal and a mood * * @author <NAME> * @date 3/11/2021 * * @param valence - the valence value * @param arousal - the arousal value * @param m - the score of the NPC */ EmotionComponent(float valence, float arousal, Mood m); /** * @fn GetEmotion * * @brief Gets and returns the current emotion * * @author <NAME> * @date 3/11/2021 * * @return Current Emotion */ Emotion GetEmotion() { return m_State; } /** * @fn SetEmotion * * @brief Sets the emotion to the emotion provided as a parameter * * @author <NAME> * @date 3/11/2021 * * @param e */ void SetEmotion(Emotion e) { m_State = e; } /** * @fn GetMood * * @brief Gets and returns the current mood * * @author <NAME> * @date 3/11/2021 * * @return Current Mood */ Mood GetMood() { return m_Mood; } /** * @fn GetArousal * * @brief Gets the arousal of the emotion * * @author <NAME> * @date 3/11/2021 * * @return float - the arousal value */ float GetArousal(); /** * @fn SetArousal * * @brief Sets the arousal of the emotion to the given value * * @author <NAME> * @date 3/11/2021 * * @param arousal */ void SetArousal(float arousal); /** * @fn GetValence * * @brief Gets the valence value of the emotion * * @author <NAME> * @date 3/11/2021 * * @return the valence value */ float GetValence(); /** * @fn SetValence * * @brief Sets the Valence of the emotion to the given value * * @author <NAME> * @date 3/11/2021 * * @param valence */ void SetValence(float valence); /** * @fn IncreaseArousal * * @brief Increases arousal by the value given * * @author <NAME> * @date 3/11/2021 * * @param arousal */ void IncreaseArousal(float arousal); /** * @fn DecreaseArousal * * @brief decreases arousal by the value given * * @author <NAME> * @date 3/11/2021 * * @param arousal */ void DecreaseArousal(float arousal); /** * @fn IncreaseValence * * @brief increases valence by the value given * * @author <NAME> * @date 3/11/2021 * * @param valence */ void IncreaseValence(float valence); /** * @fn DecreaseValence * * @brief decreases arousal by the value given * * @author <NAME> * @date 3/11/2021 * * @param valence */ void DecreaseValence(float valence); //Returns the Arousal and Valence of a given Emotion /** * @fn ReturnEmotion * * @brief Returns the emotion in the emotionMap that corresponds to the given arousal and valence values * * @author <NAME> * @date 3/11/2021 * * @param arousal * @param valence * @return Emotion */ Emotion ReturnEmotion(float arousal, float valence); //checks if emotion is present in map, otherwise adds the emotion to the map /** * @fn AddEmotion * * @brief Adds an emotion into the emotionMap using the given arousal, valence and Emotion name (Emotion enum name must be in Enum list to allow for this to work) * * @author <NAME> * @date 3/11/2021 * * @param arousal * @param valence * @param e */ void AddEmotion(float arousal, float valence, Emotion e); /** * @fn RemoveEmotion * * @brief Removes the emotion from the map that has the matching arousal and valence values * * @author <NAME> * @date 3/11/2021 * * @param arousal * @param valence */ void RemoveEmotion(float arousal, float valence); /** * @fn AddTrait * * @brief Adds a trait to the personality vector * * @author <NAME> * @date 3/11/2021 * * @param t */ void AddTrait(Trait t); /** * @fn Update * * @brief Updates the EmotionComponent with deltaTime * * @author <NAME> * @date 3/11/2021 * * @param dt - DeltaTime */ void Update(float dt); /** * @fn GetScaledArousal * * @brief Gets the scaled arousal value * * @author <NAME> * @date 3/11/2021 * * @param value * @return scaled arousal value */ float GetScaledArousal(float value); /** * @fn GetScaledValence * * @brief Gets the scaled valence value * * @author <NAME> * @date 3/11/2021 * * @param value * @return scaled valence value */ float GetScaledValence(float value); /** * @fn GetPositiveValenceMultiplier * * @brief Gets the positve valence multiplier * * @author <NAME> * @date 3/11/2021 * * @return the Positive Valence multiplier */ float GetPositiveValenceMultiplier() { return m_MultiplierPositiveValence; } /** * @fn GetNegativeValenceMultiplier * * @brief Gets the negative valence multiplier * * @author <NAME> * @date 3/11/2021 * * @return the negative valence multiplier */ float GetNegativeValenceMultiplier() { return m_MultiplierNegativeValence; } /** * @fn GetPositiveArosualMultiplier * * @brief Gets the positive arousal multiplier * * @author <NAME> * @date 3/11/2021 * * @return the positive arousal multiplier */ float GetPositiveArosualMultiplier() { return m_MultiplierPositiveArousal; } /** * @fn GetNegativeArousalMultiplier * * @brief Gets the negative arousal multiplier * * @author <NAME> * @date 3/11/2021 * * @return the negative arousal multiplier */ float GetNegativeArousalMultiplier() { return m_MultiplierNegativeArousal; } /** * @fn SetMood * * @brief Sets the mood to the given mood value * * @author <NAME> * @date 3/11/2021 * * @param m - refers to the mood being set */ void SetMood(Mood m); /** * @fn GetCurrentEmotionAsString * * @brief Gets the current emotion and returns it as a string * * @author <NAME> * @date 3/11/2021 * * @return string that references the current emotion */ std::string GetCurrentEmotionAsString(); /** * @fn GetCurrentMoodAsString * * @brief Gets the current mood and returns it as a string * * @author <NAME> * @date 3/11/2021 * * @return string that contains the name of the current mood */ std::string GetCurrentMoodAsString(); /** * @fn GetTraitAsString * * @brief Gets the trait at the given position and returns it as a string * * @author <NAME> * @date 3/11/2021 * * @param pos - the positon in the personality trait vector you want to get * @return string that contains the name of the trait at the given position */ std::string GetTraitAsString(int pos); /** * @fn GetTraitsAsString * * @brief Calls the GetTraitAsString function numerous times to get all the active traits as a string * * @author <NAME> * @date 3/11/2021 * * @return a string for each trait currently active */ std::string GetTraitsAsString(); /** * @fn UpdateTimer * * @brief Updates the internalTimer back to its default value * * @author <NAME> * @date 3/11/2021 * */ void UpdateTimer() {internalTimer = 15.0f;} private: /** * @fn InitialiseMap * * @brief Initialises the map with all the emotions used * * @author <NAME> * @date 3/11/2021 * */ void InitialiseMap(); /** * @fn UpdateMood * * @brief Updates the mood when required * * @author <NAME> * @date 3/11/2021 * * @param dt - deltaTime */ void UpdateMood(float dt); /// A map containing all available emotions, with the key being the Emotion valence and arousal std::map <std::pair<float,float>, Emotion> EmotionMap; /// an iterator for the emotion map std::map <std::pair<float, float>, Emotion>::iterator it = EmotionMap.begin(); /// arousal value float m_Arousal = 0.0f; /// valence value float m_Valence = 0.0f; /// positive valence multiplier float m_MultiplierPositiveValence = 1.0f; /// negative valence multiplier float m_MultiplierNegativeValence = 1.0f; /// positive arousal multiplier float m_MultiplierPositiveArousal = 1.0f; /// negative arousal multiplier float m_MultiplierNegativeArousal = 1.0f; /// Current Emotional State Emotion m_State = Emotion::Neutral; /// Current Mood Mood m_Mood = Mood::Neutral; /// Vector of all traits of the AI - AKA its Personality std::vector<Trait> m_Traits; /// iterator std::vector<Trait>::iterator itr; /// internal timer used to assist with changing moods float internalTimer = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Light/DirectionalLight.h
#pragma once #include "TNAH/Renderer/Light.h" namespace tnah { class DirectionLight : public Light { public: /** * * \fn void DirectionLight * * \brief Default constructor * * \author <NAME> * \date 13/9/2021 * * * */ DirectionLight(); /** * * \fn void DirectionLight * * \brief Constructor of the light * * \author <NAME> * \date 13/9/2021 * * \param direction Light Direction * \param ambient Light ambient * \param diffuse Light diffuse * \param specular Light specular * * */ DirectionLight(const glm::vec3& direction, const glm::vec3& ambient,const glm::vec3& diffuse,const glm::vec3& specular); /** * * \fn void ~DirectionLight * * \brief Default deconstructor * * \author <NAME> * \date 13/9/2021 * * * */ virtual ~DirectionLight() {} /** * * \fn void SetUpLight * * \brief Sets up the light with given inputs. * * \author <NAME> * \date 13/9/2021 * * \param direction Light Direction * \param ambient Light ambient * \param diffuse Light diffuse * \param specular Light specular * * */ void SetUpLight(const glm::vec3& direction, const glm::vec3& ambient,const glm::vec3& diffuse,const glm::vec3& specular); }; }
BryceStandley/TNAH
core/src/Platform/OpenGL/OpenGLVertexArray.h
<filename>core/src/Platform/OpenGL/OpenGLVertexArray.h #pragma once #include "TNAH/Core/Ref.h" #include "TNAH/Renderer/VertexArray.h" namespace tnah { /** * @class OpenGLVertexArray * * @brief An OpenGLVertexArray class that inherits from base class VertexArray. * * @author <NAME> * @date 7/09/2021 */ class OpenGLVertexArray : public VertexArray { public: /** * @fn OpenGLVertexArray::OpenGLVertexArray(); * * @brief Default constructor that generates the vertex array * * @author <NAME> * @date 7/09/2021 */ OpenGLVertexArray(); /** * @fn virtual OpenGLVertexArray::~OpenGLVertexArray(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~OpenGLVertexArray(); /** * @fn void OpenGLVertexArray::Bind() const override; * * @brief Binds this object * * @author <NAME> * @date 7/09/2021 */ void Bind() const override; /** * @fn void OpenGLVertexArray::Unbind() const override; * * @brief Unbinds this object * * @author <NAME> * @date 7/09/2021 */ void Unbind() const override; /** * @fn void OpenGLVertexArray::SetID(const uint32_t& id) override * * @brief Sets an identifier * * @author <NAME> * @date 7/09/2021 * * @param id The identifier. */ void SetID(const uint32_t& id) override { m_RendererID = id; } /** * @fn void OpenGLVertexArray::AddVertexBuffer(const Ref<VertexBuffer>& vertexBuffer) override; * * @brief Adds a vertex buffer * * @author <NAME> * @date 7/09/2021 * * @param vertexBuffer Buffer for vertex data. */ void AddVertexBuffer(const Ref<VertexBuffer>& vertexBuffer) override; /** * @fn void OpenGLVertexArray::SetIndexBuffer(const Ref<IndexBuffer>& indexBuffer) override; * * @brief Sets index buffer * * @author <NAME> * @date 7/09/2021 * * @param indexBuffer Buffer for index data. */ void SetIndexBuffer(const Ref<IndexBuffer>& indexBuffer) override; /** * @fn void OpenGLVertexArray::SetIndexSize(const uint32_t& size) override * * @brief Sets index size * * @author <NAME> * @date 7/09/2021 * * @param size The size. */ void SetIndexSize(const uint32_t& size) override { m_IndexSize = size; } /** * * @brief Gets vertex buffers * * @author <NAME> * @date 7/09/2021 * * @returns std::vector<Ref<VertexBuffer>>& */ const std::vector<Ref<VertexBuffer>>& GetVertexBuffers() const override { return m_VertexBuffers; } /** * @fn virtual const Ref<IndexBuffer>& OpenGLVertexArray::GetIndexBuffer() const * * @brief Gets index buffer * * @author <NAME> * @date 7/09/2021 * * @returns The index buffer. */ virtual const Ref<IndexBuffer>& GetIndexBuffer() const { return m_IndexBuffer; } /** * @fn uint32_t OpenGLVertexArray::GetIndexSize() const override * * @brief Gets index size * * @author <NAME> * @date 7/09/2021 * * @returns The index size. */ uint32_t GetIndexSize() const override { return m_IndexSize; } void UpdateVertexBuffer() override; private: /** @brief Identifier for the renderer */ uint32_t m_RendererID; /** @brief The vertex contains pointers belonging to multiple vertex buffers */ std::vector<Ref<VertexBuffer>> m_VertexBuffers; /** @brief Pointer to the Buffer for index data */ Ref<IndexBuffer> m_IndexBuffer; /** @brief Size of the index */ uint32_t m_IndexSize = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Events/DebugEvent.h
<reponame>BryceStandley/TNAH<gh_stars>1-10 #pragma once #include "TNAH/Core/Core.h" #include "TNAH/Events/Event.h" namespace tnah { /** * @class DebugEvent * * @brief A debug event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class DebugEvent : public Event { public: /** * @fn std::pair<std::string, std::string> DebugEvent::GetDetails() * * @brief Gets the name and description details and stores them as a pair * * @author <NAME> * @date 10/09/2021 * * @returns The details. */ std::pair<std::string, std::string> GetDetails() { return { m_Name, m_Description }; } EVENT_CLASS_CATEGORY(EventCategoryDebugCore | EventCategoryDebugApp) protected: /** @brief The name */ std::string m_Name; /** @brief The description */ std::string m_Description; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/RendererAPI.h
<gh_stars>1-10 #pragma once #include <TNAH/Core/Core.h> #include "TNAH/Renderer/VertexArray.h" namespace tnah { /** * @enum CullMode * * @brief Values that represent cull modes */ enum class CullMode { Front = 0, Back = 1, Front_And_Back = 2, Disabled = 3 }; /** * @enum DepthFunc * * @brief Values that represent depth Functions */ enum class DepthFunc { Never, Less, Equal, Lequal, Greater, NotEqual, Gequal, Always }; /** * @enum APIEnum * * @brief Values that represent API enums */ enum class APIEnum { CullFace, DepthTest, DepthMask, FrontFace_CW, FrontFace_CCW, CubeMap }; /** * @enum DrawMode * * @brief Different modes for drawing */ enum class DrawMode { Points, Lines, Line_Strip, Line_Loop, Line_Strip_Adjacency, Lines_Adjacency, Triangle_Strip, Triangle_Fan, Triangles, Triangles_Strip_Adjacency, Triangles_Adjacency, Patches }; /** * @class RendererAPI * * @brief A renderer API class that provides the functions required to render, regardless of API used * * @author <NAME> * @date 12/09/2021 */ class RendererAPI { public: /** * @enum API * * @brief Values that represent apis */ enum class API { None = 0, OpenGL = 1 }; /** * @fn virtual RendererAPI::~RendererAPI() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~RendererAPI() = default; /** * @fn virtual void RendererAPI::Init() = 0; * * @brief Initializes this object * * @author <NAME> * @date 12/09/2021 */ virtual void Init() = 0; /** * @fn virtual void RendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0; * * @brief Sets a viewport * * @author <NAME> * @date 12/09/2021 * * @param x An uint32_t to process. * @param y An uint32_t to process. * @param width The width. * @param height The height. */ virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0; /** * @fn virtual void RendererAPI::SetClearColor(const glm::vec4& color) = 0; * * @brief Sets clear color * * @author <NAME> * @date 12/09/2021 * * @param color The color. */ virtual void SetClearColor(const glm::vec4& color) = 0; /** * @fn virtual void RendererAPI::Clear() = 0; * * @brief Clears this object to its blank/initial state * * @author <NAME> * @date 12/09/2021 */ virtual void Clear() = 0; /** * @fn virtual void RendererAPI::Disable(const APIEnum& value) = 0; * * @brief Disables the given value * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void Disable(const APIEnum& value) = 0; /** * @fn virtual void RendererAPI::Enable(const APIEnum& value) = 0; * * @brief Enables the given value * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void Enable(const APIEnum& value) = 0; ; /** * @fn virtual void RendererAPI::DrawArray(const Ref<VertexArray>& vertexArray, const DrawMode& mode = DrawMode::Triangles) = 0; * * @brief Draws a vertex array * * @author <NAME> * @date 12/09/2021 * * @param vertexArray The VertexArray object to be bound and drawn from. * @param mode The draw mode of the VertexArray. Default to DrawMode::Triangles */ virtual void DrawArray(const Ref<VertexArray>& vertexArray, const DrawMode& mode = DrawMode::Triangles) = 0; /** * @fn virtual void RendererAPI::DrawIndexed(const Ref<VertexArray>& vertexArray, const DrawMode& mode = DrawMode::Triangles, void* indicesStart = nullptr) = 0; * * @brief Draw indexed * * @author <NAME> * @date 12/09/2021 * * @param vertexArray Array of vertices. * @param mode The draw mode of the VertexArray. Default to DrawMode::Triangles * @param indicesStart Starting position of the indices. */ virtual void DrawIndexed(const Ref<VertexArray>& vertexArray, const DrawMode& mode = DrawMode::Triangles, void* indicesStart = nullptr) = 0; /** * @fn virtual void RendererAPI::SetWireframe(const bool& enable) = 0; * * @brief Sets a wireframe * * @author Bryce Standley * @date 12/09/2021 * * @param enable True to enable, false to disable. */ virtual void SetWireframe(const bool& enable) = 0; /** * @fn virtual bool RendererAPI::CheckFullScreen(const int& width, const int& height) = 0; * * @brief Check full screen * * @author <NAME> * @date 12/09/2021 * * @param width The width. * @param height The height. * * @returns True if it succeeds, false if it fails. */ virtual bool CheckFullScreen(const int& width, const int& height) = 0; /** * @fn virtual void RendererAPI::SetCullMode(const CullMode& mode) = 0; * * @brief Sets cull mode * * @author <NAME> * @date 12/09/2021 * * @param mode The mode. */ virtual void SetCullMode(const CullMode& mode) = 0; /** * @fn virtual void RendererAPI::SetDepthMask(const bool& enabled) = 0; * * @brief Sets depth mask * * @author <NAME> * @date 12/09/2021 * * @param enabled True to enable, false to disable. */ virtual void SetDepthMask(const bool& enabled) = 0; /** * @fn virtual void RendererAPI::SetDepthFunc(const DepthFunc& enabled) = 0; * * @brief Sets depth function * * @author <NAME> * @date 12/09/2021 * * @param enabled The enabled. */ virtual void SetDepthFunc(const DepthFunc& enabled) = 0; /** * @fn static API RendererAPI::GetAPI() * * @brief Gets api * * @author <NAME> * @date 12/09/2021 * * @returns api. */ static API GetAPI() { return s_API; } /** * @fn static Scope<RendererAPI> RendererAPI::Create(); * * @brief Creates a unique ptr to the API ; * * @author <NAME> * @date 12/09/2021 * * @returns A unique ptr to the API; */ static Scope<RendererAPI> Create(); protected: /** * * \fn int ModeFromDrawMode * * \brief Gets the mode from a given DrawMode. This is intended to be overwritten by a derived API class. * * \author <NAME> * \date 13/9/2021 * * \param mode The mode to get. * * \return int value of the API mode. * */ virtual int ModeFromDrawMode(const DrawMode& mode) = 0; private: /** @brief The API */ static API s_API; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/Components.h
<filename>core/src/TNAH/Scene/Components/Components.h #pragma once #include <TNAH/Core/Core.h> #include "TNAH/Core/KeyCodes.h" #include "TNAH/Core/UUID.h" #include "ComponentIdentification.h" #include "TNAH/Scene/SceneCamera.h" #include "SkyboxComponent.h" #include "TerrainComponent.h" #include "PhysicsComponents.h" #include "LightComponents.h" #include "AudioComponents.h" #include "AI/Affordance.h" #include "AI/AIComponent.h" #include "AI/CharacterComponent.h" #include "AI/PlayerInteractions.h" #include "TNAH/Renderer/Mesh.h" #define GLM_ENABLE_EXPERIMENTAL #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtx/quaternion.hpp> #include "TNAH/Core/Input.h" #include "TNAH/Core/Math.h" namespace tnah { /**********************************************************************************************//** * @class IDComponent * * @brief An identifier component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class IDComponent { public: UUID ID = 0; private: friend class EditorUI; inline static std::string s_SearchString = "id component"; inline static ComponentTypes s_Types = { {ComponentVariations::ID}, {{ComponentCategory::Core}} }; }; /**********************************************************************************************//** * @class TagComponent * * @brief A tag component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class TagComponent { public: std::string Tag; /**********************************************************************************************//** * @fn TagComponent::TagComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ TagComponent() = default; /**********************************************************************************************//** * @fn TagComponent::TagComponent(const TagComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ TagComponent(const TagComponent& other) = default; /**********************************************************************************************//** * @fn TagComponent::TagComponent(const std::string& tag) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param tag The tag. **************************************************************************************************/ TagComponent(const std::string& tag) : Tag(tag) {} /**********************************************************************************************//** * @fn operator std::string& () * * @brief Cast that converts the given to a string&amp; * * @author Chris * @date 10/09/2021 * * @returns The result of the operation. **************************************************************************************************/ operator std::string& () { return Tag; } /**********************************************************************************************//** * @fn operator const std::string& () const * * @brief Gets the string&amp; * * @author Chris * @date 10/09/2021 * * @returns A const. **************************************************************************************************/ operator const std::string& () const { return Tag; } private: friend class EditorUI; inline static std::string s_SearchString = "tag component"; inline static ComponentTypes s_Types= { {ComponentVariations::Tag}, {{ComponentCategory::Core}} }; }; /**********************************************************************************************//** * @class RelationshipComponent * * @brief A relationship component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class RelationshipComponent { public: /** @brief Handle of the parent */ UUID ParentHandle = 0; /** @brief The children */ std::vector<UUID> Children; /**********************************************************************************************//** * @fn RelationshipComponent::RelationshipComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ RelationshipComponent() = default; /**********************************************************************************************//** * @fn RelationshipComponent::RelationshipComponent(const RelationshipComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ RelationshipComponent(const RelationshipComponent& other) = default; /**********************************************************************************************//** * @fn RelationshipComponent::RelationshipComponent(UUID parent) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param parent The parent. **************************************************************************************************/ RelationshipComponent(UUID parent) : ParentHandle(parent) {} private: friend class EditorUI; inline static std::string s_SearchString = "relationship component"; inline static ComponentTypes s_Types= { {ComponentVariations::Relationship}, {{ComponentCategory::Core}} }; }; /**********************************************************************************************//** * @class TransformComponent * * @brief Transform component, placed on every object to give it a real transform in the scene * i.e. Position, Rotation and Scale. Including a raw 4x4 matrix transform (mat4) * matrix for rendering * * @author <NAME> * @date 20/07/2021 **************************************************************************************************/ class TransformComponent { public: /** @brief The position */ glm::vec3 Position = { 0.0f, 0.0f, 0.0f }; /** @brief The rotation */ glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f }; glm::quat QuatRotation = {1.0f, 0.0f, 0.0f, 0.0f}; /** @brief The scale */ glm::vec3 Scale = { 1.0f, 1.0f, 1.0f }; /** @brief The up */ glm::vec3 Up = { 0.0f, 1.0f, 0.0f }; /** @brief The right */ glm::vec3 Right = { 1.0f, 0.0f, 0.0f }; /** @brief The forward */ glm::vec3 Forward = { 0.0f, 0.0f, -1.0f }; /**********************************************************************************************//** * @fn TransformComponent::TransformComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ TransformComponent() = default; /**********************************************************************************************//** * @fn TransformComponent::TransformComponent(const TransformComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ TransformComponent(const TransformComponent& other) = default; /**********************************************************************************************//** * @fn TransformComponent::TransformComponent(const glm::vec3& position) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param position The position. **************************************************************************************************/ TransformComponent(const glm::vec3& position) : Position(position) {} /**********************************************************************************************//** * @fn TransformComponent::TransformComponent(const glm::vec3& position, const glm::vec3& rotation,const glm::vec3& scale) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param position The position. * @param rotation The rotation. * @param scale The scale. **************************************************************************************************/ TransformComponent(const glm::vec3& position, const glm::vec3& rotation,const glm::vec3& scale) :Position(position), Rotation(rotation), Scale(scale) {} /**********************************************************************************************//** * @fn glm::mat4 TransformComponent::GetTransform() const * * @brief Gets the transform * * @author Chris * @date 10/09/2021 * * @returns The transform. **************************************************************************************************/ glm::mat4 GetTransform() const { return glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale); } glm::mat4 GetQuatTransform() const { return glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(QuatRotation) * glm::scale(glm::mat4(1.0f), Scale); } private: friend class EditorUI; inline static std::string s_SearchString = "transform component"; inline static ComponentTypes s_Types= { {ComponentVariations::Transform}, {{ComponentCategory::Core}} }; }; /**********************************************************************************************//** * @enum CameraClearMode * * @brief Values that represent camera clear modes **************************************************************************************************/ enum class CameraClearMode { Skybox, Color, None}; /**********************************************************************************************//** * @struct CameraComponent * * @brief A camera component that holds all the required information for a camera * * @author Nukee * @date 3/08/2021 **************************************************************************************************/ class CameraComponent { public: /** @brief The camera */ SceneCamera Camera; /** @brief The clear mode */ CameraClearMode ClearMode = CameraClearMode::Skybox; /** @brief The clear color */ glm::vec4 ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f }; /** @brief True to primary */ bool Primary = true; /**********************************************************************************************//** * @fn void CameraComponent::SetClearMode(const CameraClearMode& mode) * * @brief Sets clear mode * * @author Chris * @date 10/09/2021 * * @param mode The mode. **************************************************************************************************/ void SetClearMode(const CameraClearMode& mode) { if(mode != ClearMode) { ClearMode = mode; m_UpdatedClear = true; } } /**********************************************************************************************//** * @fn CameraComponent::CameraComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ CameraComponent() = default; /**********************************************************************************************//** * @fn CameraComponent::CameraComponent(const CameraComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ CameraComponent(const CameraComponent& other) = default; /**********************************************************************************************//** * @fn CameraComponent::CameraComponent(const SceneCamera& camera) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param camera The camera. **************************************************************************************************/ CameraComponent(const SceneCamera& camera) { Camera = camera; } /**********************************************************************************************//** * @fn operator CameraComponent::SceneCamera& () * * @brief Cast that converts the given to a SceneCamera&amp; * * @author Chris * @date 10/09/2021 * * @returns The result of the operation. **************************************************************************************************/ operator SceneCamera& () { return Camera; } /**********************************************************************************************//** * @fn operator const CameraComponent::SceneCamera& () const * * @brief Scene camera&amp; * * @author Chris * @date 10/09/2021 * * @returns A const. **************************************************************************************************/ operator const SceneCamera& () const { return Camera; } private: /** @brief True to updated clear */ bool m_UpdatedClear = false; inline static std::string s_SearchString = "camera component"; inline static ComponentTypes s_Types = { {ComponentVariations::Camera}, {{ComponentCategory::Camera, ComponentCategory::Rendering}} }; friend class EditorUI; }; /**********************************************************************************************//** * @struct MeshComponent * * @brief A mesh component holds all the information to do with 3D meshes * * @author <NAME> * @date 3/08/2021 **************************************************************************************************/ class MeshComponent { public: /** @brief The model */ Ref<Model> Model = nullptr; /**********************************************************************************************//** * @fn MeshComponent::MeshComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ MeshComponent() = default; /**********************************************************************************************//** * @fn MeshComponent::MeshComponent(const std::string& modelPath) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param modelPath Full pathname of the model file. **************************************************************************************************/ MeshComponent(const std::string& modelPath) { Model = Model::Create(modelPath); } /**********************************************************************************************//** * @fn MeshComponent::MeshComponent(const MeshComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ MeshComponent(const MeshComponent& other) = default; /**********************************************************************************************//** * @fn MeshComponent::MeshComponent(Ref<tnah::Model> model) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param model The model. **************************************************************************************************/ MeshComponent(Ref<tnah::Model> model) : Model(model) { } /**********************************************************************************************//** * @fn void MeshComponent::LoadMesh(const std::string& modelPath) * * @brief Loads a mesh * * @author Chris * @date 10/09/2021 * * @param modelPath Full pathname of the model file. **************************************************************************************************/ void LoadMesh(const std::string& modelPath) { Model = Model::Create(modelPath); }; /**********************************************************************************************//** * @fn operator Ref<tnah::Model>() const * * @brief Cast that converts the given to a Model> * * @author Chris * @date 10/09/2021 * * @returns The result of the operation. **************************************************************************************************/ operator Ref<tnah::Model>() const { return Model; } private: friend class EditorUI; inline static std::string s_SearchString = "mesh component"; inline static ComponentTypes s_Types = { {ComponentVariations::Mesh}, {{ComponentCategory::Rendering, ComponentCategory::Objects}} }; }; /**********************************************************************************************//** * @enum MovementType * * @brief Values that represent movement types **************************************************************************************************/ enum class MovementType { Direct, Physics }; /**********************************************************************************************//** * @class PlayerControllerComponent * * @brief A player controller component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class PlayerControllerComponent { public: /** @brief The forward */ KeyCode Forward = Key::W; /** @brief The backward */ KeyCode Backward = Key::S; /** @brief The left */ KeyCode Left = Key::A; /** @brief The right */ KeyCode Right = Key::D; /** @brief The sprint */ std::pair<KeyCode, KeyCode> Sprint = {Key::LeftShift, Key::RightShift}; /** @brief The jump */ KeyCode Jump = Key::Space; /** @brief The crouch */ KeyCode Crouch = Key::C; /** @brief The movement style */ MovementType MovementStyle = MovementType::Direct; /** @brief Height of the player */ float PlayerHeight = 3.5f; /** @brief The movement speed */ float MovementSpeed = 5.0f; /** @brief The rotation sensitivity */ float RotationSensitivity = 0.1f; /** @brief The sprint speed */ float SprintSpeed = 10.0f; /** @brief The crouch speed */ float CrouchSpeed = 2.5f; /** @brief The crouch height multiplier */ float CrouchHeightMultiplier = 0.5f; /**********************************************************************************************//** * @fn PlayerControllerComponent::PlayerControllerComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ PlayerControllerComponent() = default; /**********************************************************************************************//** * @fn bool PlayerControllerComponent::IsSprinting() const * * @brief Query if this object is sprinting * * @author Chris * @date 10/09/2021 * * @returns True if sprinting, false if not. **************************************************************************************************/ bool IsSprinting() const { return Input::IsKeyPressed(Sprint.first) || Input::IsKeyPressed(Sprint.second); } /**********************************************************************************************//** * @fn bool PlayerControllerComponent::IsCrouched() const * * @brief Query if this object is crouched * * @author Chris * @date 10/09/2021 * * @returns True if crouched, false if not. **************************************************************************************************/ bool IsCrouched() const { return Input::IsKeyPressed(Crouch); } /**********************************************************************************************//** * @fn bool PlayerControllerComponent::IsJumping() const * * @brief Query if this object is jumping * * @author Chris * @date 10/09/2021 * * @returns True if jumping, false if not. **************************************************************************************************/ bool IsJumping() const { return Input::IsKeyPressed(Jump); } /**********************************************************************************************//** * @fn bool PlayerControllerComponent::IsMoving() const * * @brief Query if this object is moving * * @author Chris * @date 10/09/2021 * * @returns True if moving, false if not. **************************************************************************************************/ bool IsMoving() const { return Input::IsKeyPressed(Forward) || Input::IsKeyPressed(Backward) || Input::IsKeyPressed(Left) || Input::IsKeyPressed(Right); } /**********************************************************************************************//** * @fn void PlayerControllerComponent::SetActive(const bool& active) * * @brief Sets an active * * @author Chris * @date 10/09/2021 * * @param active True to active. **************************************************************************************************/ void SetActive(const bool& active) { m_Active = active; } /**********************************************************************************************//** * @fn bool PlayerControllerComponent::IsActive() const * * @brief Query if this object is active * * @author Chris * @date 10/09/2021 * * @returns True if active, false if not. **************************************************************************************************/ bool IsActive() const{ return m_Active; } private: /**********************************************************************************************//** * @fn void PlayerControllerComponent::ProcessMouseRotation(TransformComponent& transform) * * @brief Process the mouse rotation described by transform * * @author Chris * @date 10/09/2021 * * @param [in,out] transform The transform. **************************************************************************************************/ void ProcessMouseRotation(TransformComponent& transform) { const auto [fst, snd] = Input::GetMousePos(); if (m_FirstMouseInput) { m_LastMouseXPos = fst; m_LastMouseYPos = snd; m_FirstMouseInput = false; } float offsetX = fst - m_LastMouseXPos; float offsetY = m_LastMouseYPos - snd; m_LastMouseXPos = fst; m_LastMouseYPos = snd; offsetX *= RotationSensitivity; offsetY *= RotationSensitivity; transform.Rotation.x += offsetX; transform.Rotation.y -= offsetY; if (transform.Rotation.y > 89.0f) { transform.Rotation.y = 89.0f; } if (transform.Rotation.y < -89.0f) { transform.Rotation.y = -89.0f; } } /** @brief True to active */ bool m_Active = true; /** @brief True to first mouse input */ bool m_FirstMouseInput = true; /** @brief The last mouse x coordinate position */ float m_LastMouseXPos = 0.0f; /** @brief The last mouse y coordinate position */ float m_LastMouseYPos = 0.0f; /** @brief True to disable, false to enable the mouse */ bool m_MouseDisabled = false; inline static std::string s_SearchString = "player controller component"; inline static ComponentTypes s_Types = { {ComponentVariations::PlayerController}, {{ComponentCategory::Controls, ComponentCategory::Objects}} }; friend class Scene; friend class EditorUI; }; /**********************************************************************************************//** * @class EditorCameraComponent * * @brief An editor camera component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class EditorCameraComponent { public: /** @brief The editor camera */ SceneCamera EditorCamera; /** @brief The clear mode */ CameraClearMode ClearMode = CameraClearMode::Skybox; /** @brief The clear color */ glm::vec4 ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f }; /** @brief True to primary */ bool Primary = true; /**********************************************************************************************//** * @fn void EditorCameraComponent::SetClearMode(const CameraClearMode& mode) * * @brief Sets clear mode * * @author Chris * @date 10/09/2021 * * @param mode The mode. **************************************************************************************************/ void SetClearMode(const CameraClearMode& mode) { if(mode != ClearMode) { ClearMode = mode; } } /**********************************************************************************************//** * @fn EditorCameraComponent::EditorCameraComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ EditorCameraComponent() = default; /**********************************************************************************************//** * @fn EditorCameraComponent::EditorCameraComponent(const EditorCameraComponent& other) = default; * * @brief Defaulted copy constructor * * @author Chris * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ EditorCameraComponent(const EditorCameraComponent& other) = default; /**********************************************************************************************//** * @fn operator EditorCameraComponent::SceneCamera& () * * @brief Cast that converts the given to a SceneCamera&amp; * * @author Chris * @date 10/09/2021 * * @returns The result of the operation. **************************************************************************************************/ operator SceneCamera& () { return EditorCamera; } /**********************************************************************************************//** * @fn operator const EditorCameraComponent::SceneCamera& () const * * @brief Scene camera&amp; * * @author Chris * @date 10/09/2021 * * @returns A const. **************************************************************************************************/ operator const SceneCamera& () const { return EditorCamera; } private: inline static std::string s_SearchString = "editor camera component"; inline static ComponentTypes s_Types = { {ComponentVariations::EditorCamera}, {{ComponentCategory::Core, ComponentCategory::Camera, ComponentCategory::Editor}} }; friend class Scene; friend class EditorUI; }; /** * @class EditorComponent * * @brief A component that's placed on a editor camera to control and maintain editor related controls and values. * * @author <NAME> * @date 21/08/2021 */ class EditorComponent { public: /**********************************************************************************************//** * @fn EditorComponent::EditorComponent() = default; * * @brief Defaulted constructor * * @author Chris * @date 10/09/2021 **************************************************************************************************/ EditorComponent() = default; private: /**********************************************************************************************//** * @enum EditorMode * * @brief Values that represent editor modes **************************************************************************************************/ enum class EditorMode { Edit, Play, Pause }; /** @brief The editor mode */ EditorMode m_EditorMode = EditorMode::Edit; /** @brief True if is empty, false if not */ bool m_IsEmpty = true; /** @brief The search string */ inline static std::string s_SearchString = "editor component"; inline static ComponentTypes s_Types = { {ComponentVariations::Editor}, {{ComponentCategory::Core, ComponentCategory::Editor}} }; friend class Scene; friend class EditorLayer; friend class EditorUI; friend class Editor; }; /**********************************************************************************************//** * @struct NativeScript * * @brief A native script component allows the user to create overrides that will attach to the * game object. Native scripts are written in C++ and provided within the application using * the engine. * * @author <NAME> * @date 20/07/2021 **************************************************************************************************/ class NativeScriptComponent { public: std::string Script; NativeScriptComponent() = default; NativeScriptComponent(const std::string& scriptPath) :Script(scriptPath) {} private: friend class EditorUI; inline static std::string s_SearchString = ""; inline static ComponentTypes s_Types = { {ComponentVariations::NativeScript}, {{ComponentCategory::Script, ComponentCategory::Custom}} }; }; /**********************************************************************************************//** * @struct CSharpScript * * @brief A C# script component allows the user to create overrides attached to the game object * within the application using the engine. A C# script is written in C# and provided * within the application using the engine. * * @author <NAME> * @date 20/07/2021 **************************************************************************************************/ struct CSharpScript { }; }
BryceStandley/TNAH
core/src/Platform/Windows/WinInput.h
<filename>core/src/Platform/Windows/WinInput.h #pragma once #include "TNAH/Core/Core.h" #include "TNAH/Core/Input.h" #include <GLFW/glfw3.h> namespace tnah { /** * @class WinInput * * @brief A Window Input class that inherits from the base Input class * * @author <NAME> * @date 7/09/2021 */ class WinInput : public Input { protected: /** * @fn virtual bool WinInput::IsKeyPressedImpl(int keycode) override; * * @brief Query if 'keycode' is pressed implementation * * @author <NAME> * @date 7/09/2021 * * @param keycode The keycode. * * @returns True if key pressed, false if not. */ virtual bool IsKeyPressedImpl(int keycode) override; /** * @fn virtual bool WinInput::IsMouseButtonPressedImpl(int button) override; * * @brief Query if 'button' is mouse button pressed * * @author <NAME> * @date 7/09/2021 * * @param button The button. * * @returns True if mouse button pressed, false if not. */ virtual bool IsMouseButtonPressedImpl(int button) override; /** * @fn virtual float WinInput::GetMouseXImpl() override; * * @brief Gets mouse x coordinate implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse x coordinate implementation. */ virtual float GetMouseXImpl() override; /** * @fn virtual float WinInput::GetMouseYImpl() override; * * @brief Gets mouse y coordinate implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse y coordinate implementation. */ virtual float GetMouseYImpl() override; /** * @fn virtual std::pair<float, float> WinInput::GetMousePosImpl() override; * * @brief Gets mouse position implementation * * @author <NAME> * @date 7/09/2021 * * @returns The mouse position implementation. */ virtual std::pair<float, float> GetMousePosImpl() override; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Camera.h
#pragma once #include <glm/glm.hpp> namespace tnah { /** * @class Camera * * @brief A camera class responsible for setting up the application camera * * @author <NAME> * @date 12/09/2021 */ class Camera { public: /** * @fn Camera::Camera() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ Camera() = default; /** * @fn Camera::Camera(const glm::mat4& projectionMatrix); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param projectionMatrix The projection matrix. */ Camera(const glm::mat4& projectionMatrix); /** * @fn virtual Camera::~Camera() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Camera() = default; /** * @fn const glm::mat4& Camera::GetProjectionMatrix() const * * @brief Gets projection matrix * * @author <NAME> * @date 12/09/2021 * * @returns The projection matrix. */ const glm::mat4& GetProjectionMatrix() const { return m_ProjectionMatrix; } /** * @fn void Camera::SetProjectionMatrix(const glm::mat4& projectionMatrix) * * @brief Sets projection matrix * * @author <NAME> * @date 12/09/2021 * * @param projectionMatrix The projection matrix. */ void SetProjectionMatrix(const glm::mat4& projectionMatrix) { m_ProjectionMatrix = projectionMatrix; } /** * @fn float Camera::GetExposure() const * * @brief Gets the exposure * * @author <NAME> * @date 12/09/2021 * * @returns The exposure. */ float GetExposure() const { return m_Exposure; } /** * @fn float& Camera::GetExposure() * * @brief Gets the exposure * * @author <NAME> * @date 12/09/2021 * * @returns The exposure. */ float& GetExposure() { return m_Exposure; } /** * @fn const glm::mat4& Camera::GetViewProjectionMatrix() const * * @brief Gets view projection matrix * * @author <NAME> * @date 12/09/2021 * * @returns The view projection matrix. */ const glm::mat4& GetViewProjectionMatrix() const { return m_ViewProjection; } /** @brief Pointer to the main camera */ static Camera* Main; protected: /** * @fn static void Camera::SetMainCamera(Camera& other); * * @brief Sets main camera * * @author <NAME> * @date 12/09/2021 * * @param [in,out] other The other. */ static void SetMainCamera(Camera& other); /** @brief The main camera */ static Camera* MainCamera; /** @brief The projection matrix */ glm::mat4 m_ProjectionMatrix = glm::mat4(1.0f); /** @brief The exposure */ float m_Exposure = 0.8f; /** @brief The invert transform view matrix */ glm::mat4 m_InvertTransformViewMatrix = glm::mat4(1.0f); /** @brief The view matrix */ glm::mat4 m_ViewMatrix = glm::mat4(1.0f); /** @brief The view projection matrix */ glm::mat4 m_ViewProjection = m_ProjectionMatrix * m_ViewMatrix; friend class Scene; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Shader.h
<reponame>BryceStandley/TNAH #pragma once #include <string> #include <glm/glm.hpp> #include "TNAH/Core/Ref.h" namespace tnah { /** * @enum ShaderUniformType * * @brief Values that represent shader uniform types */ enum class ShaderUniformType { None = 0, Bool, Int, UInt, Float, Vec2, Vec3, Vec4, Mat3, Mat4, IVec2, IVec3, IVec4 }; /** * @class ShaderUniform * * @brief Form for viewing the shader uniform. * * @author <NAME> * @date 12/09/2021 */ class ShaderUniform { public: /** * @fn ShaderUniform::ShaderUniform() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ ShaderUniform() = default; /** * @fn ShaderUniform::ShaderUniform(std::string name, ShaderUniformType type, uint32_t size, uint32_t offset); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param type The type. * @param size The size. * @param offset The offset. */ ShaderUniform(std::string name, ShaderUniformType type, uint32_t size, uint32_t offset); /** * @fn const std::string& ShaderUniform::GetName() const * * @brief Gets the name * * @author <NAME> * @date 12/09/2021 * * @returns The name. */ const std::string& GetName() const { return m_Name; } /** * @fn ShaderUniformType ShaderUniform::GetType() const * * @brief Gets the type * * @author <NAME> * @date 12/09/2021 * * @returns The type. */ ShaderUniformType GetType() const { return m_Type; } /** * @fn uint32_t ShaderUniform::GetSize() const * * @brief Gets the size * * @author <NAME> * @date 12/09/2021 * * @returns The size. */ uint32_t GetSize() const { return m_Size; } /** * @fn uint32_t ShaderUniform::GetOffset() const * * @brief Gets the offset * * @author <NAME> * @date 12/09/2021 * * @returns The offset. */ uint32_t GetOffset() const { return m_Offset; } /** * @fn static const std::string& ShaderUniform::UniformTypeToString(ShaderUniformType type); * * @brief Uniform type to string * * @author <NAME> * @date 12/09/2021 * * @param type The type. * * @returns A reference to a const std::string. */ static const std::string& UniformTypeToString(ShaderUniformType type); private: /** @brief The name */ std::string m_Name; /** @brief The type */ ShaderUniformType m_Type = ShaderUniformType::None; /** @brief The size */ uint32_t m_Size = 0; /** @brief The offset */ uint32_t m_Offset = 0; }; /** * @enum ShaderDomain * * @brief Values that represent shader domains */ enum class ShaderDomain { None = 0, Vertex = 0, Pixel = 1 // unused }; /** * @class ShaderResourceDeclaration * * @brief A shader resource declaration class. * * @author <NAME> * @date 12/09/2021 */ class ShaderResourceDeclaration { public: /** * @fn ShaderResourceDeclaration::ShaderResourceDeclaration() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ ShaderResourceDeclaration() = default; /** * @fn ShaderResourceDeclaration::ShaderResourceDeclaration(const std::string& name, uint32_t resourceRegister, uint32_t count) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param resourceRegister The resource register. * @param count Number of. */ ShaderResourceDeclaration(const std::string& name, uint32_t resourceRegister, uint32_t count) : m_Name(name), m_Register(resourceRegister), m_Count(count) {} /** * @fn virtual ShaderResourceDeclaration::~ShaderResourceDeclaration(); * * @brief Destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~ShaderResourceDeclaration(); /** * @fn virtual const std::string& ShaderResourceDeclaration::GetName() const * * @brief Gets the name * * @author <NAME> * @date 12/09/2021 * * @returns The name. */ virtual const std::string& GetName() const { return m_Name; } /** * @fn virtual uint32_t ShaderResourceDeclaration::GetRegister() const * * @brief Gets the register * * @author <NAME> * @date 12/09/2021 * * @returns The register. */ virtual uint32_t GetRegister() const { return m_Register; } /** * @fn virtual uint32_t ShaderResourceDeclaration::GetCount() const * * @brief Gets the count * * @author <NAME> * @date 12/09/2021 * * @returns The count. */ virtual uint32_t GetCount() const { return m_Count; } private: /** @brief The name */ std::string m_Name; /** @brief The register */ uint32_t m_Register = 0; /** @brief The count */ uint32_t m_Count = 0; }; /** * @typedef std::vector<ShaderResourceDeclaration*> ShaderResourceList * * @brief Defines a vector of shader resources */ typedef std::vector<ShaderResourceDeclaration*> ShaderResourceList; /** * @class Shader * * @brief A shader class which is used to access shaders * * @author <NAME> * @date 12/09/2021 */ class Shader : public RefCounted { public: /** * @fn virtual Shader::~Shader() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Shader() = default; /** * @fn virtual void Shader::Bind() = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() = 0; /** * @fn virtual void Shader::Unbind() = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() = 0; /** * @fn virtual bool Shader::IsBound() const = 0; * * @brief Query if this object is bound * * @author <NAME> * @date 12/09/2021 * * @returns True if bound, false if not. */ virtual bool IsBound() const = 0; /** * @fn virtual void Shader::SetBool(const std::string& name, bool value) = 0; * * @brief Sets a bool * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value True to value. */ virtual void SetBool(const std::string& name, bool value) = 0; /** * @fn virtual void Shader::SetInt(const std::string& name, int value) = 0; * * @brief Sets an int * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetInt(const std::string& name, int value) = 0; /** * @fn virtual void Shader::SetFloat(const std::string& name, float value) = 0; * * @brief Sets a float * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetFloat(const std::string& name, float value) = 0; /** * @fn virtual void Shader::SetVec2(const std::string& name, const glm::vec2& value) = 0; * * @brief Sets vector 2 * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetVec2(const std::string& name, const glm::vec2& value) = 0; /** * @fn virtual void Shader::SetVec3(const std::string& name, const glm::vec3& value) = 0; * * @brief Sets vector 3 * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetVec3(const std::string& name, const glm::vec3& value) = 0; /** * @fn virtual void Shader::SetVec4(const std::string& name, const glm::vec4& value) = 0; * * @brief Sets vector 4 * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetVec4(const std::string& name, const glm::vec4& value) = 0; /** * @fn virtual void Shader::SetMat3(const std::string& name, const glm::mat3& value) = 0; * * @brief Sets matrix 3 * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetMat3(const std::string& name, const glm::mat3& value) = 0; /** * @fn virtual void Shader::SetMat4(const std::string& name, const glm::mat4& value) = 0; * * @brief Sets matrix 4 * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param value The value. */ virtual void SetMat4(const std::string& name, const glm::mat4& value) = 0; /** * @fn virtual const std::string& Shader::GetName() const = 0; * * @brief Gets the name * * @author <NAME> * @date 12/09/2021 * * @returns The name. */ virtual const std::string& GetName() const = 0; /** * @fn static Ref<Shader> Shader::Create(const std::string& filePath); * * @brief Creates a new Shader * * @author <NAME> * @date 12/09/2021 * * @param filePath Full pathname of the file. * * @returns A pointer to a shader */ static Ref<Shader> Create(const std::string& filePath); /** * @fn static Ref<Shader> Shader::Create(const std::string& vertexSrc, const std::string& fragmentSrc); * * @brief Creates a new Shader * * @author <NAME> * @date 12/09/2021 * * @param vertexSrc The vertex source. * @param fragmentSrc The fragment source. * * @returns A pointer to a shader */ static Ref<Shader> Create(const std::string& vertexSrc, const std::string& fragmentSrc); /** * @fn static Ref<Shader> Shader::CheckShaderExists(const std::string& filePath); * * @brief Queries if a given shader exists * * @author <NAME> * @date 12/09/2021 * * @param filePath Full pathname of the file. * * @returns A Ref&lt;Shader&gt; */ static Ref<Shader> CheckShaderExists(const std::string& filePath); /** * @fn static Ref<Shader> Shader::CheckShaderExists(const std::string& vertexSrc, const std::string& fragmentSrc); * * @brief Queries if a given shaders exist * * @author <NAME> * @date 12/09/2021 * * @param vertexSrc The vertex source. * @param fragmentSrc The fragment source. * * @returns A Ref&lt;Shader&gt; */ static Ref<Shader> CheckShaderExists(const std::string& vertexSrc, const std::string& fragmentSrc); /** @brief The file paths */ std::pair<std::string, std::string> m_FilePaths; /** @brief Name of the shader */ std::string m_ShaderName; friend class EditorUI; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/CharacterComponent.h
<gh_stars>1-10 #pragma once namespace tnah { /** * @brief enums that represent the three NPC types */ enum class CharacterNames { None = 0, Rubbish = 1, StudentAi = 2, DogAi = 3 }; struct CharacterComponent { /** * @fn CharacterComponent * * @brief default constructor of the character component struct * * @author <NAME> * @date 2/11/2021 * */ CharacterComponent() { } /** * @fn CharacterComponent * * @brief Constructor for the character component that takes in the character type name and sets the character accordingly * * @author <NAME> * @date 2/11/2021 * * @param characterType * @param character */ CharacterComponent(CharacterNames characterType, Character* character) { SetCharacter(characterType, character); } /** * @fn SetCharacter * * @brief Sets the character using the given characterType name * * @author <NAME> * @date 2/11/2021 * * @param characterType * @param character */ void SetCharacter(CharacterNames characterType, Character* character) { if(character) { switch (characterType) { case CharacterNames::StudentAi: aiCharacter = character; break; case CharacterNames::DogAi: aiCharacter = character; break; case CharacterNames::Rubbish: aiCharacter = character; break; case CharacterNames::None: aiCharacter = nullptr; break; default: break; } currentCharacter = characterType; } } /// A pointer to the an instance of character class Ref<Character> aiCharacter = nullptr; /// character name value of the current character CharacterNames currentCharacter = CharacterNames::None; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Bone.h
#pragma once #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtx/quaternion.hpp> #include <vector> #include <string> #include <Assimp/anim.h> namespace tnah { /** * @struct KeyPosition * * @brief A key position. * * @author <NAME> * @date 12/09/2021 */ struct KeyPosition { /** @brief The position */ glm::vec3 position; /** @brief The time stamp */ float timeStamp; }; /** * @struct KeyRotation * * @brief A key rotation. * * @author <NAME> * @date 12/09/2021 */ struct KeyRotation { /** @brief The orientation */ glm::quat orientation; /** @brief The time stamp */ float timeStamp; }; /** * @struct KeyScale * * @brief A key scale. * * @author <NAME> * @date 12/09/2021 */ struct KeyScale { /** @brief The scale */ glm::vec3 scale; /** @brief The time stamp */ float timeStamp; }; /** * @class Bone * * @brief A bone class responsible for handling the bones used in animation * * @author <NAME> * @date 12/09/2021 */ class Bone { private: /** @brief The positions */ std::vector<KeyPosition> m_Positions; /** @brief The rotations */ std::vector<KeyRotation> m_Rotations; /** @brief The scales */ std::vector<KeyScale> m_Scales; /** @brief Number of positions */ int m_NumPositions; /** @brief Number of rotations */ int m_NumRotations; /** @brief Number of scalings */ int m_NumScalings; /** @brief The local transform */ glm::mat4 m_LocalTransform; /** @brief The name */ std::string m_Name; /** @brief The identifier */ int m_ID; public: /** * @fn Bone::Bone(const std::string& name, int ID, const aiNodeAnim* channel) * * @brief Constructor that reads keyframes from aiNodeAnim. * * @author <NAME> * @date 12/09/2021 * * @param name The name. * @param ID The identifier. * @param channel The channel. */ Bone(const std::string& name, int ID, const aiNodeAnim* channel) : m_Name(name), m_ID(ID), m_LocalTransform(1.0f) { m_NumPositions = channel->mNumPositionKeys; for (int positionIndex = 0; positionIndex < m_NumPositions; ++positionIndex) { aiVector3D aiPosition = channel->mPositionKeys[positionIndex].mValue; float timeStamp = channel->mPositionKeys[positionIndex].mTime; KeyPosition data; //data.position = AssimpGLMHelpers::GetGLMVec(aiPosition); data.timeStamp = timeStamp; m_Positions.push_back(data); } m_NumRotations = channel->mNumRotationKeys; for (int rotationIndex = 0; rotationIndex < m_NumRotations; ++rotationIndex) { aiQuaternion aiOrientation = channel->mRotationKeys[rotationIndex].mValue; float timeStamp = channel->mRotationKeys[rotationIndex].mTime; KeyRotation data; //data.orientation = AssimpGLMHelpers::GetGLMQuat(aiOrientation); data.timeStamp = timeStamp; m_Rotations.push_back(data); } m_NumScalings = channel->mNumScalingKeys; for (int keyIndex = 0; keyIndex < m_NumScalings; ++keyIndex) { aiVector3D scale = channel->mScalingKeys[keyIndex].mValue; float timeStamp = channel->mScalingKeys[keyIndex].mTime; KeyScale data; //data.scale = AssimpGLMHelpers::GetGLMVec(scale); data.timeStamp = timeStamp; m_Scales.push_back(data); } } /* Interpolates b/w positions,rotations & scaling keys based on the curren time of the animation and prepares the local transformation matrix by combining all keys tranformations */ /** * @fn void Bone::Update(float animationTime) * * @brief Updates the given animationTime by interpolating between position, rotation, scale and combining them all together to form the localTransform * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. */ void Update(float animationTime) { glm::mat4 translation = InterpolatePosition(animationTime); glm::mat4 rotation = InterpolateRotation(animationTime); glm::mat4 scale = InterpolateScaling(animationTime); m_LocalTransform = translation * rotation * scale; } /** * @fn glm::mat4 Bone::GetLocalTransform() * * @brief Gets local transform * * @author <NAME> * @date 12/09/2021 * * @returns The local transform. */ glm::mat4 GetLocalTransform() { return m_LocalTransform; } /** * @fn std::string Bone::GetBoneName() const * * @brief Gets bone name * * @author <NAME> * @date 12/09/2021 * * @returns The bone name. */ std::string GetBoneName() const { return m_Name; } /** * @fn int Bone::GetBoneID() * * @brief Gets bone identifier * * @author <NAME> * @date 12/09/2021 * * @returns The bone identifier. */ int GetBoneID() { return m_ID; } /** * @fn int Bone::GetPositionIndex(float animationTime) * * @brief Gets the index of the position to interpolate to based on the current animation time * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns The position index. */ int GetPositionIndex(float animationTime) { for (int index = 0; index < m_NumPositions - 1; ++index) { if (animationTime < m_Positions[index + 1].timeStamp) return index; } assert(0); return 0; } /** * @fn int Bone::GetRotationIndex(float animationTime) * * @brief Gets the index of the rotation to interpolate to based on the current animation time * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns The rotation index. */ int GetRotationIndex(float animationTime) { for (int index = 0; index < m_NumRotations - 1; ++index) { if (animationTime < m_Rotations[index + 1].timeStamp) return index; } assert(0); return 0; } /** * @fn int Bone::GetScaleIndex(float animationTime) * * @brief Gets the index of the scale to interpolate to based on the current animation time * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns The scale index. */ int GetScaleIndex(float animationTime) { for (int index = 0; index < m_NumScalings - 1; ++index) { if (animationTime < m_Scales[index + 1].timeStamp) return index; } assert(0); return 0; } private: /** * @fn float Bone::GetScaleFactor(float lastTimeStamp, float nextTimeStamp, float animationTime) * * @brief Gets scale factor * * @author <NAME> * @date 12/09/2021 * * @param lastTimeStamp The last time stamp. * @param nextTimeStamp The next time stamp. * @param animationTime The animation time. * * @returns The scale factor. */ float GetScaleFactor(float lastTimeStamp, float nextTimeStamp, float animationTime) { float scaleFactor = 0.0f; float midWayLength = animationTime - lastTimeStamp; float framesDiff = nextTimeStamp - lastTimeStamp; scaleFactor = midWayLength / framesDiff; return scaleFactor; } /** * @fn glm::mat4 Bone::InterpolatePosition(float animationTime) * * @brief Interpolate position * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns A glm::mat4. */ glm::mat4 InterpolatePosition(float animationTime) { if (1 == m_NumPositions) return glm::translate(glm::mat4(1.0f), m_Positions[0].position); int p0Index = GetPositionIndex(animationTime); int p1Index = p0Index + 1; float scaleFactor = GetScaleFactor(m_Positions[p0Index].timeStamp, m_Positions[p1Index].timeStamp, animationTime); glm::vec3 finalPosition = glm::mix(m_Positions[p0Index].position, m_Positions[p1Index].position, scaleFactor); return glm::translate(glm::mat4(1.0f), finalPosition); } /** * @fn glm::mat4 Bone::InterpolateRotation(float animationTime) * * @brief Interpolate rotation * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns A glm::mat4. */ glm::mat4 InterpolateRotation(float animationTime) { if (1 == m_NumRotations) { auto rotation = glm::normalize(m_Rotations[0].orientation); return glm::toMat4(rotation); } int p0Index = GetRotationIndex(animationTime); int p1Index = p0Index + 1; float scaleFactor = GetScaleFactor(m_Rotations[p0Index].timeStamp, m_Rotations[p1Index].timeStamp, animationTime); glm::quat finalRotation = glm::slerp(m_Rotations[p0Index].orientation, m_Rotations[p1Index].orientation, scaleFactor); finalRotation = glm::normalize(finalRotation); return glm::toMat4(finalRotation); } /** * @fn glm::mat4 Bone::InterpolateScaling(float animationTime) * * @brief Interpolate scaling * * @author <NAME> * @date 12/09/2021 * * @param animationTime The animation time. * * @returns A glm::mat4. */ glm::mat4 InterpolateScaling(float animationTime) { if (1 == m_NumScalings) return glm::scale(glm::mat4(1.0f), m_Scales[0].scale); int p0Index = GetScaleIndex(animationTime); int p1Index = p0Index + 1; float scaleFactor = GetScaleFactor(m_Scales[p0Index].timeStamp, m_Scales[p1Index].timeStamp, animationTime); glm::vec3 finalScale = glm::mix(m_Scales[p0Index].scale, m_Scales[p1Index].scale, scaleFactor); return glm::scale(glm::mat4(1.0f), finalScale); } }; }
BryceStandley/TNAH
core/src/TNAH/Layers/Layer.h
<filename>core/src/TNAH/Layers/Layer.h #pragma once #include "TNAH/Core/Core.h" #include "TNAH/Events/Event.h" #include "TNAH/Core/Timestep.h" #include "TNAH/Physics/PhysicsTimestep.h" namespace tnah { /** * @class Layer * * @brief The layer class is used to allow for the creation of layers, which allow for things to be rendered and/or events to be received on multiple different layers. * * @author <NAME> * @date 10/09/2021 */ class Layer { public: /** * @fn Layer::Layer(const std::string& name = "Layer"); * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param name (Optional) The name. */ Layer(const std::string& name = "Layer"); /** * @fn virtual Layer::~Layer() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 10/09/2021 */ virtual ~Layer() = default; /** * @fn virtual void Layer::OnAttach() * * @brief Executes when the layer is attached * * @author <NAME> * @date 10/09/2021 */ virtual void OnAttach() {} /** * @fn virtual void Layer::OnDetach() * * @brief Executes when the layer is detached * * @author <NAME> * @date 10/09/2021 */ virtual void OnDetach() {} /** * @fn virtual void Layer::OnUpdate(Timestep ts) * * @brief Executes on update * * @author <NAME> * @date 10/09/2021 * * @param ts The timestep. */ virtual void OnUpdate(Timestep ts) {} /** * @fn virtual void Layer::OnFixedUpdate(PhysicsTimestep ps) * * @brief Executes on fixed update (for physics purposes) * * @author <NAME> * @date 10/09/2021 * * @param ps The physicsTimestep. */ virtual void OnFixedUpdate(Timestep ts, PhysicsTimestep ps) {} /** * @fn virtual void Layer::OnImGuiRender() * * @brief Executes when imgui renders * * @author <NAME> * @date 10/09/2021 */ virtual void OnImGuiRender() {} /** * @fn virtual void Layer::OnEvent(Event& event) * * @brief Executes when an event occurs * * @author <NAME> * @date 10/09/2021 * * @param [in,out] event The event. */ virtual void OnEvent(Event& event) {} /** * @fn const std::string& Layer::GetName() const * * @brief Gets the name * * @author <NAME> * @date 10/09/2021 * * @returns The name. */ const std::string& GetName() const { return m_DebugName; } protected: /** @brief DebugName of the layer */ std::string m_DebugName; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Material.h
#pragma once #include "TNAH/core/Core.h" #include "TNAH/Renderer/Shader.h" #include "TNAH/Renderer/Texture.h" namespace tnah { /** * @struct MaterialProperties * * @brief A material properties struct. * * @author <NAME> * @date 12/09/2021 */ struct MaterialProperties { /** @brief The shininess */ float Shininess = 32.0f; /** @brief The metalness */ float Metalness = 0.0f; /** * @fn MaterialProperties() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ MaterialProperties() = default; /** * @fn MaterialProperties(float shine, float metal) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shine The shine. * @param metal The metal. */ MaterialProperties(float shine, float metal) :Shininess(shine), Metalness(metal) {} }; class Material : public RefCounted { public: /** * @fn static Ref<Material> Material::Create(const Ref<Shader>& shader); * * @brief Creates a new material * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * * @returns A pointer to the material */ static Ref<Material> Create(const Ref<Shader>& shader); /** * @fn static Ref<Material> Material::Create(const Ref<Shader>& shader, const MaterialProperties& properties); * * @brief Creates a new material * * @author <NAME>andley * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. * * @returns A pointer to the material */ static Ref<Material> Create(const Ref<Shader>& shader, const MaterialProperties& properties); /** * @fn static Ref<Material> Material::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); * * @brief Creates a new material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * * @returns A pointer to the material */ static Ref<Material> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); /** * @fn static Ref<Material> Material::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); * * @brief Creates a new material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. * * @returns A pointer to the material */ static Ref<Material> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); /** * @fn static Ref<Material> Material::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); * * @brief Creates a new material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param shininess The shininess. * @param metalness The metalness. * * @returns A pointer to the material */ static Ref<Material> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); /** * @fn void Material::SetTextures(std::vector<Ref<Texture2D>> textures); * * @brief Sets the textures * * @author <NAME> * @date 12/09/2021 * * @param textures The textures. */ void SetTextures(std::vector<Ref<Texture2D>> textures); /** * @fn void Material::AddTexture(Ref<Texture2D> texture) * * @brief Adds a texture to the material. * * @author <NAME> * @date 27/10/2021 * * @param texture The texture to add. * */ void AddTexture(Ref<Texture2D> texture) { m_Textures.push_back(texture); } /** * @fn virtual void Material::BindTextures(); * * @brief Bind textures * * @author <NAME> * @date 12/09/2021 */ virtual void BindTextures(); /** * @fn virtual void Material::BindShader(); * * @brief Bind shader * * @author <NAME> * @date 12/09/2021 */ virtual void BindShader(); /** * @fn virtual void Material::UnBindShader(); * * @brief Unbind shader * * @author <NAME> * @date 12/09/2021 */ virtual void UnBindShader(); /** * @fn virtual Ref<Shader> Material::GetShader() const * * @brief Gets the shader * * @author <NAME> * @date 12/09/2021 * * @returns The shader. */ virtual Ref<Shader> GetShader() const { return m_Shader; } /** * @fn std::vector<Ref<Texture2D>> Material::GetTextures() const * * @brief Gets the textures * * @author <NAME> * @date 12/09/2021 * * @returns The textures. */ std::vector<Ref<Texture2D>> GetTextures() const { return m_Textures; } /** * @fn virtual MaterialProperties& Material::GetProperties() * * @brief Gets the properties * * @author <NAME> * @date 12/09/2021 * * @returns The properties. */ virtual MaterialProperties& GetProperties() { return m_Properties; } /** * @fn virtual Material::~Material(); * * @brief Destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Material(); /** * @fn Material::Material(); * * @brief Default constructor * * @author <NAME> * @date 12/09/2021 */ Material(); /** * @fn Material::Material(const Ref<Shader>& shader); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. */ Material(const Ref<Shader>& shader); /** * @fn Material::Material(const Ref<Shader>& shader, const MaterialProperties& properties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. */ Material(const Ref<Shader>& shader, const MaterialProperties& properties); /** * @fn Material::Material(const MaterialProperties& properties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param properties The properties. */ Material(const MaterialProperties& properties); /** * @fn Material::Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. */ Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); /** * @fn Material::Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. */ Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); /** * @fn Material::Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param shininess The shininess. * @param metalness The metalness. */ Material(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); protected: /** @brief The shader */ Ref<Shader> m_Shader; /** @brief The properties */ MaterialProperties m_Properties; private: /** @brief The textures */ std::vector<Ref<Texture2D>> m_Textures; friend class EditorUI; }; /** * @class SkyboxMaterial * * @brief A skybox material class that inherits from the material class * * @author <NAME> * @date 12/09/2021 */ class SkyboxMaterial : public Material { public: /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const Ref<Shader>& shader); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const Ref<Shader>& shader); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const Ref<Shader>& shader, const Texture3DProperties& cubemapProperties); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param cubemapProperties The cubemap properties. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const Ref<Shader>& shader, const Texture3DProperties& cubemapProperties); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const Ref<Shader>& shader, const MaterialProperties& properties); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const Ref<Shader>& shader, const MaterialProperties& properties); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const Ref<Shader>& shader, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. * @param cubemapProperties The cubemap properties. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const Ref<Shader>& shader, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. * @param cubemapProperties The cubemap properties. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); /** * @fn static Ref<SkyboxMaterial> SkyboxMaterial::Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); * * @brief Creates a new Skybox Material * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param shininess The shininess. * @param metalness The metalness. * * @returns A pointer to the material */ static Ref<SkyboxMaterial> Create(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); /** * @fn void SkyboxMaterial::BindTextures() override; * * @brief Bind textures * * @author <NAME> * @date 12/09/2021 */ void BindTextures() override; /** * @fn SkyboxMaterial::SkyboxMaterial(const Ref<Shader>& shader); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. */ SkyboxMaterial(const Ref<Shader>& shader); /** * @fn SkyboxMaterial::SkyboxMaterial(const Ref<Shader>& shader, const Texture3DProperties& cubemapProperties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param cubemapProperties The cubemap properties. */ SkyboxMaterial(const Ref<Shader>& shader, const Texture3DProperties& cubemapProperties); /** * @fn SkyboxMaterial::SkyboxMaterial(const Ref<Shader>& shader, const MaterialProperties& properties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. */ SkyboxMaterial(const Ref<Shader>& shader, const MaterialProperties& properties); /** * @fn SkyboxMaterial::SkyboxMaterial(const Ref<Shader>& shader, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); * * @brief Constructor * * @author <NAME>andley * @date 12/09/2021 * * @param shader The shader. * @param properties The properties. * @param cubemapProperties The cubemap properties. */ SkyboxMaterial(const Ref<Shader>& shader, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); /** * @fn SkyboxMaterial::SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. */ SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); /** * @fn SkyboxMaterial::SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. */ SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties); /** * @fn SkyboxMaterial::SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param properties The properties. * @param cubemapProperties The cubemap properties. */ SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const MaterialProperties& properties, const Texture3DProperties& cubemapProperties); /** * @fn SkyboxMaterial::SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param vertexShaderPath Full pathname of the vertex shader file. * @param fragmentShaderPath Full pathname of the fragment shader file. * @param shininess The shininess. * @param metalness The metalness. */ SkyboxMaterial(const std::string& vertexShaderPath, const std::string& fragmentShaderPath, const float& shininess, const float& metalness); /** * @fn Ref<Texture3D> SkyboxMaterial::GetCubemapTextures() const * * @brief Gets cubemap textures * * @author <NAME> * @date 12/09/2021 * * @returns The cubemap textures. */ Ref<Texture3D> GetCubemapTextures() const { return m_Cubemap; } /** * @fn Texture3DProperties SkyboxMaterial::GetCubemapProperties() const * * @brief Gets cubemap properties * * @author <NAME> * @date 12/09/2021 * * @returns The cubemap properties. */ Texture3DProperties GetCubemapProperties() const { return m_CubemapProperties; } /** * @fn SkyboxMaterial::~SkyboxMaterial() override; * * @brief Destructor * * @author <NAME> * @date 12/09/2021 */ ~SkyboxMaterial() override; private: /** @brief The cubemap properties */ Texture3DProperties m_CubemapProperties; /** @brief The cubemap */ Ref<Texture3D> m_Cubemap; }; }
BryceStandley/TNAH
core/src/TNAH/Audio/AudioAPI.h
#pragma #include "TNAH/Scene/Components/AudioComponents.h" #include "TNAH/Scene/Components/Components.h" namespace tnah { /** * @class AudioAPI * * @brief An abstract audioAPI class that contains virtual functions that the audio class will inherit * * @author <NAME> * @date 7/09/2021 */ class AudioAPI { public: /** * @fn virtual bool AudioAPI::SetListener(TransformComponent &transforms) const = 0; * * @brief Sets a listener * * @author <NAME> * @date 7/09/2021 * * @param [in,out] transforms The transform. * * @returns True if it succeeds, false if it fails. */ virtual bool SetListener(TransformComponent &transforms) const = 0; /** * @fn virtual bool AudioAPI::AddAudioSource(AudioSourceComponent &sound) = 0; * * @brief Adds an audio source * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * * @returns True if it succeeds, false if it fails. */ virtual bool AddAudioSource(AudioSourceComponent &sound) = 0; /** * @fn virtual bool AudioAPI::UpdateAudioSource(AudioSourceComponent &sound) = 0; * * @brief Updates the audio source described by sound * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * * @returns True if it succeeds, false if it fails. */ virtual bool UpdateAudioSource(AudioSourceComponent &sound) = 0; /** * @fn virtual void AudioAPI::OnUpdate() = 0; * * @brief Executes the action on update * * @author <NAME> * @date 7/09/2021 */ virtual void OnUpdate() = 0; /** * @fn virtual void AudioAPI::UpdateSound(AudioSourceComponent& sound, TransformComponent &transforms) = 0; * * @brief Updates the sound * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound. * @param [in,out] transforms The transforms. */ virtual void UpdateSound(AudioSourceComponent& sound, TransformComponent &transforms) = 0; /** * @fn virtual bool AudioAPI::Active() const = 0; * * @brief Actives this object * * @author <NAME> * @date 7/09/2021 * * @returns True if it succeeds, false if it fails. */ virtual bool Active() const = 0; /** * @fn virtual void AudioAPI::Clear() = 0; * * @brief Clears this object to its blank/initial state * * @author <NAME> * @date 7/09/2021 */ virtual void Clear() = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Events/MouseEvent.h
#pragma once #include "TNAH/Events/Event.h" #include "TNAH/Core/MouseCodes.h" namespace tnah { /** * @class MouseMovedEvent * * @brief A mouse moved event class that inherits from the base event class * * @author <NAME> * @date 10/09/2021 */ class MouseMovedEvent : public Event { public: /** * @fn MouseMovedEvent::MouseMovedEvent(const float x, const float y) * * @brief Constructor for the mouse moved event * * @author <NAME> * @date 10/09/2021 * * @param x The x coordinate of the mouse. * @param y The y coordinate of the mouse. */ MouseMovedEvent(const float x, const float y) : m_MouseX(x), m_MouseY(y) {} /** * @fn float MouseMovedEvent::GetX() const * * @brief Get x coordinate of the mouse * * @author <NAME> * @date 10/09/2021 * * @returns The x coordinate. */ float GetX() const { return m_MouseX; } /** * @fn float MouseMovedEvent::GetY() const * * @brief Get y coordinate of the mouse * * @author <NAME> * @date 10/09/2021 * * @returns The y coordinate. */ float GetY() const { return m_MouseY; } /** * @fn std::string MouseMovedEvent::ToString() const override * * @brief Convert the mouse x and y coordinates into a string representation * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ std::string ToString() const override { std::stringstream ss; ss << "MouseMovedEvent: " << m_MouseX << ", " << m_MouseY; return ss.str(); } EVENT_CLASS_TYPE(MouseMoved) EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput) private: /** @brief The mouse x and y coordinates */ float m_MouseX, m_MouseY; }; /** * @class MouseScrolledEvent * * @brief A mouse scrolled event that inherits from the Event class * * @author <NAME> * @date 10/09/2021 */ class MouseScrolledEvent : public Event { public: /** * @fn MouseScrolledEvent::MouseScrolledEvent(const float xOffset, const float yOffset) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param xOffset The offset on the x-axis. * @param yOffset The offset on the y-axis. */ MouseScrolledEvent(const float xOffset, const float yOffset) : m_XOffset(xOffset), m_YOffset(yOffset) {} /** * @fn float MouseScrolledEvent::GetXOffset() const * * @brief Gets x coordinate offset * * @author <NAME> * @date 10/09/2021 * * @returns The x coordinate offset. */ float GetXOffset() const { return m_XOffset; } /** * @fn float MouseScrolledEvent::GetYOffset() const * * @brief Gets y coordinate offset * * @author <NAME> * @date 10/09/2021 * * @returns The y coordinate offset. */ float GetYOffset() const { return m_YOffset; } /** * @fn std::string MouseScrolledEvent::ToString() const override * * @brief Convert the x and y offset of the the event into a string * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ std::string ToString() const override { std::stringstream ss; ss << "MouseScrolledEvent: " << GetXOffset() << ", " << GetYOffset(); return ss.str(); } EVENT_CLASS_TYPE(MouseScrolled) EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput) private: /** @brief The x and y offset */ float m_XOffset, m_YOffset; }; /** * @class MouseButtonEvent * * @brief A mouse button event class that inherits from the base Event class * * @author <NAME> * @date 10/09/2021 */ class MouseButtonEvent : public Event { public: /** * @fn MouseCode MouseButtonEvent::GetMouseButton() const * * @brief Gets mouse button * * @author <NAME> * @date 10/09/2021 * * @returns The mouse button. */ MouseCode GetMouseButton() const { return m_Button; } EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput | EventCategoryMouseButton) protected: /** * @fn tnah::MouseButtonEvent::MouseButtonEvent(const MouseCode button) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param button The button. */ MouseButtonEvent(const MouseCode button) : m_Button(button) {} /** @brief The button */ MouseCode m_Button; }; /** * @class MouseButtonPressedEvent * * @brief A mouse button pressed event class that inherits from the MouseButtonEvent class * * @author <NAME> * @date 10/09/2021 */ class MouseButtonPressedEvent : public MouseButtonEvent { public: /** * @fn MouseButtonPressedEvent::MouseButtonPressedEvent(const MouseCode button) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param button The button. */ MouseButtonPressedEvent(const MouseCode button) : MouseButtonEvent(button) {} /** * @fn std::string MouseButtonPressedEvent::ToString() const override * * @brief Converts the mouse button code into a string representation * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ std::string ToString() const override { std::stringstream ss; ss << "MouseButtonPressedEvent: " << m_Button; return ss.str(); } EVENT_CLASS_TYPE(MouseButtonPressed) }; /** * @class MouseButtonReleasedEvent * * @brief A mouse button released event class that inherits from the MouseButtonEvent class * * @author <NAME> * @date 10/09/2021 */ class MouseButtonReleasedEvent : public MouseButtonEvent { public: /** * @fn MouseButtonReleasedEvent::MouseButtonReleasedEvent(const MouseCode button) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param button The button. */ MouseButtonReleasedEvent(const MouseCode button) : MouseButtonEvent(button) {} /** * @fn std::string MouseButtonReleasedEvent::ToString() const override * * @brief Converts the mouse button code into a string representation * * @author <NAME> * @date 10/09/2021 * * @returns A std::string that represents this object. */ std::string ToString() const override { std::stringstream ss; ss << "MouseButtonReleasedEvent: " << m_Button; return ss.str(); } EVENT_CLASS_TYPE(MouseButtonReleased) }; }
BryceStandley/TNAH
core/src/TNAH/Layers/UI.h
<reponame>BryceStandley/TNAH<filename>core/src/TNAH/Layers/UI.h #pragma once #include "TNAH/Renderer/Texture.h" namespace tnah { /** * @class UI * * @brief UI elements based on ImGui. Predefined wrappers to make creating UI faster and more * consistent this class is designed to wrap as many ImGui functions and controls under the UI * name, simplifying functions but also making the API more flexible with what it can do and * what values it can take * * @author <NAME> * @date 01/09/2021 */ class UI { public: /** * @enum SeparatorStyle * * @brief Values that represent separator styles */ enum class SeparatorStyle { Line = 0, Space = 1 }; /** * @enum LineFlag * * @brief Values that represent line flags */ enum class LineFlag { SameLine = 0, NextLine = 1 }; /** * @enum FileBrowserMode * * @brief Values that represent file browser modes */ enum class FileBrowserMode { Open = 0, Save = 1 }; /** * @fn static void UI::Entry(const char* format, ...); * * @brief Entry function * * @author <NAME> * @date 11/09/2021 * * @param format Describes the format to use. * @param ... Variable arguments providing additional information. */ static void Entry(const char* format, ...); /** * @fn static void UI::Entry(const std::string& text); * * @brief Entry function that takes in a string of text * * @author <NAME> * @date 11/09/2021 * * @param text The text. */ static void Entry(const std::string& text); /** * @fn static void UI::Entry(const char* text, bool wrapped = false); * * @brief Entry function that takes in a const char pointer of text and a bool value to confirm if text should wrap or not * * @author <NAME> * @date 11/09/2021 * * @param text The text. * @param wrapped (Optional) True if wrapped. */ static void Entry(const char* text, bool wrapped = false); /** * @fn static void UI::Entry(const std::string& text, bool wrapped = false); * * @brief Entry function that takes in a string of text and a bool value to confirm if text should wrap or not * * @author <NAME> * @date 11/09/2021 * * @param text The text. * @param wrapped (Optional) True if wrapped. */ static void Entry(const std::string& text, bool wrapped = false); /** * @fn static bool UI::Entry(const char* label, std::string& value, bool readOnly = false, bool error = false); * * @brief Entry function that * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, std::string& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(const std::string& label, std::string& value, bool readOnly = false, bool error = false); * * @brief Entry function that takes in a label and value string, alongside bools for readOnly and error * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const std::string& label, std::string& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(const char* label, float& value, bool readOnly = false, bool error = false); * * @brief Entry function that takes in a char * label and float value string, alongside bools for readOnly and error * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, float& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(std::string& label, float& value, bool readOnly = false, bool error = false); * * @brief Entry function that takes in a string label and a float value, alongside bools for readOnly and error * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, float& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(const char* label, int& value, bool readOnly = false, bool error = false); * * @brief Entry function that takes in a char* label and an int value, alongside bools for readOnly and error * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, int& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(std::string& label, int& value, bool readOnly = false, bool error = false); * * @brief Entry function that takes in a label string and int value, alongside bools for readOnly and error * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param error (Optional) True to error. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, int& value, bool readOnly = false, bool error = false); /** * @fn static bool UI::Entry(const char* label, bool& value, bool readOnly = false); * * @brief Entry function that takes in a char* label and a bool value, alongside a bool for read only * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value True to value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, bool& value, bool readOnly = false); /** * @fn static bool UI::Entry(std::string& label, bool& value, bool readOnly = false); * * @brief Entry function that takes in a label string, alongside bools for value and readOnly * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value True to value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, bool& value, bool readOnly = false); /** * @fn static bool UI::Entry(const char* label, glm::vec2& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a char* label and glm::vec2 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, glm::vec2& value, bool readOnly = false, float resetValue = 0.0f); /** * @fn static bool UI::Entry(std::string& label, glm::vec2& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a string label and a glm::vec2 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, glm::vec2& value, bool readOnly = false, float resetValue = 0.0f); /** * @fn static bool UI::Entry(const char* label, glm::vec3& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a char* label and a glm::vec3 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, glm::vec3& value, bool readOnly = false, float resetValue = 0.0f); /** * @fn static bool UI::Entry(std::string& label, glm::vec3& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a string label and a glm::vec3 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, glm::vec3& value, bool readOnly = false, float resetValue = 0.0f); /** * @fn static bool UI::Entry(const char* label, glm::vec4& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a char* string label and a glm::vec4 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(const char* label, glm::vec4& value, bool readOnly = false, float resetValue = 0.0f); /** * @fn static bool UI::Entry(std::string& label, glm::vec4& value, bool readOnly = false, float resetValue = 0.0f); * * @brief Entry function that takes in a string label and a glm::vec4 value, alongside a bool for readOnly and a float representing the resetValue * * @author <NAME> * @date 11/09/2021 * * @param [in,out] label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Entry(std::string& label, glm::vec4& value, bool readOnly = false, float resetValue = 0.0f); //*********************** Slider Controls ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::EntrySlider(const char* label, int& value, bool readOnly = false, int min = 0, int max = 0, int resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const char* label, int& value, bool readOnly = false, int min = 0, int max = 0, int resetValue = 0); /** * @fn static bool UI::EntrySlider(const std::string& label, int& value, bool readOnly = false, int min = 0, int max = 0, int resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const std::string& label, int& value, bool readOnly = false, int min = 0, int max = 0, int resetValue = 0); /** * @fn static bool UI::EntrySlider(const char* label, float& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const char* label, float& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const std::string& label, float& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const std::string& label, float& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const char* label, glm::vec2& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const char* label, glm::vec2& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const std::string& label, glm::vec2& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const std::string& label, glm::vec2& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const char* label, glm::vec3& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const char* label, glm::vec3& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const std::string& label, glm::vec3& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const std::string& label, glm::vec3& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const char* label, glm::vec4& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const char* label, glm::vec4& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntrySlider(const std::string& label, glm::vec4& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry slider * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntrySlider(const std::string& label, glm::vec4& value, bool readOnly = false, float min = 0.0f, float max = 0.0f, float resetValue = 0); //*********************** Drag Controls ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::EntryDrag(const char* label, int& value, bool readOnly = false, int speed = 1, int min = 0, int max = 0, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const char* label, int& value, bool readOnly = false, int speed = 1, int min = 0, int max = 0, int resetValue = 0); /** * @fn static bool UI::EntryDrag(const std::string& label, int& value, bool readOnly = false, int speed = 1, int min = 0.0f, int max = 0.0f, int resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const std::string& label, int& value, bool readOnly = false, int speed = 1, int min = 0, int max = 0, int resetValue = 0); /** * @fn static bool UI::EntryDrag(const char* label, float& value, bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const char* label, float& value, bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const std::string& label, float& value, bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const std::string& label, float& value, bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const char* label, glm::vec2& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const char* label, glm::vec2& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const std::string& label, glm::vec2& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const std::string& label, glm::vec2& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const char* label, glm::vec3& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const char* label, glm::vec3& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const std::string& label, glm::vec3& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const std::string& label, glm::vec3& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const char* label, glm::vec4& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const char* label, glm::vec4& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); /** * @fn static bool UI::EntryDrag(const std::string& label, glm::vec4& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); * * @brief Entry drag * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param speed (Optional) The speed. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool EntryDrag(const std::string& label, glm::vec4& value,bool readOnly = false, float speed = 1.0f, float min = 0.0f, float max = 0.0f, float resetValue = 0); //*********************** Color Controls ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::EntryColor(const char* label, glm::vec3& value, bool readOnly = false); * * @brief Entry color * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryColor(const char* label, glm::vec3& value, bool readOnly = false); /** * @fn static bool UI::EntryColor(const std::string& label, glm::vec3& value, bool readOnly = false); * * @brief Entry color * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryColor(const std::string& label, glm::vec3& value, bool readOnly = false); /** * @fn static bool UI::EntryColor(const char* label, glm::vec4& value, bool readOnly = false); * * @brief Entry color * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryColor(const char* label, glm::vec4& value, bool readOnly = false); /** * @fn static bool UI::EntryColor(const std::string& label, glm::vec4& value, bool readOnly = false); * * @brief Entry color * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryColor(const std::string& label, glm::vec4& value, bool readOnly = false); //*********************** Checkbox Controls ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::EntryCheckbox(const char* label, bool& value, bool readOnly = false); * * @brief Entry checkbox * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value True to value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryCheckbox(const char* label, bool& value, bool readOnly = false); /** * @fn static bool UI::EntryCheckbox(const std::string& label, bool& value, bool readOnly = false); * * @brief Entry checkbox * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] value True to value. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool EntryCheckbox(const std::string& label, bool& value, bool readOnly = false); //*********************** Organisation Controls ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::EntryDropdown(const char* label, const char** options, uint32_t optionCount, uint32_t* selectedOption); * * @brief Entry dropdown * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param options Options for controlling the operation. * @param optionCount Number of options. * @param [in,out] selectedOption If non-null, the selected option. * * @returns True if it succeeds, false if it fails. */ static bool EntryDropdown(const char* label, const char** options, uint32_t optionCount, uint32_t* selectedOption); /** * @fn static bool UI::EntryDropdown(const std::string& label, const char** options, uint32_t optionCount, uint32_t* selectedOption); * * @brief Entry dropdown * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param options Options for controlling the operation. * @param optionCount Number of options. * @param [in,out] selectedOption If non-null, the selected option. * * @returns True if it succeeds, false if it fails. */ static bool EntryDropdown(const std::string& label, const char** options, uint32_t optionCount, uint32_t* selectedOption); /** * @fn static bool UI::EntryDropdown(const char* label, const std::vector<std::string>& options, uint32_t optionCount, uint32_t* selectedOption); * * @brief Entry dropdown * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param options Options for controlling the operation. * @param optionCount Number of options. * @param [in,out] selectedOption If non-null, the selected option. * * @returns True if it succeeds, false if it fails. */ static bool EntryDropdown(const char* label, const std::vector<std::string>& options, uint32_t optionCount, uint32_t* selectedOption); /** * @fn static bool UI::EntryDropdown(const std::string& label, const std::vector<std::string>& options, uint32_t optionCount, uint32_t* selectedOption); * * @brief Entry dropdown * * @author <NAME>y * @date 11/09/2021 * * @param label The label. * @param options Options for controlling the operation. * @param optionCount Number of options. * @param [in,out] selectedOption If non-null, the selected option. * * @returns True if it succeeds, false if it fails. */ static bool EntryDropdown(const std::string& label, const std::vector<std::string>& options, uint32_t optionCount, uint32_t* selectedOption); /** * @fn static bool UI::EntryCollapsable(const char* label); * * @brief Entry collapsable * * @author <NAME> * @date 11/09/2021 * * @param label The label. * * @returns True if it succeeds, false if it fails. */ static bool EntryCollapsable(const char* label); /** * @fn static bool UI::EntryCollapsable(const std::string& label); * * @brief Entry collapsable * * @author <NAME> * @date 11/09/2021 * * @param label The label. * * @returns True if it succeeds, false if it fails. */ static bool EntryCollapsable(const std::string& label); /** * @fn static bool UI::BeginTable(const char* label, int columnCount, ImGuiTableFlags flags = 0); * * @brief Begins a table * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param columnCount Number of columns. * @param flags (Optional) The flags. * * @returns True if it succeeds, false if it fails. */ static bool BeginTable(const char* label, int columnCount, ImGuiTableFlags flags = 0); /** * @fn static bool UI::BeginTable(const std::string& label, int columnCount, ImGuiTableFlags flags = 0); * * @brief Begins a table * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param columnCount Number of columns. * @param flags (Optional) The flags. * * @returns True if it succeeds, false if it fails. */ static bool BeginTable(const std::string& label, int columnCount, ImGuiTableFlags flags = 0); /** * @fn static void UI::EndTable(); * * @brief Ends a table * * @author <NAME> * @date 11/09/2021 */ static void EndTable(); //*********************** Images ++++++++++++++++++++++++++++++++// /** * @fn static void UI::Image(const Ref<Texture2D>& texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_color = ImVec4(1,1,1,1), const ImVec4& border_color = ImVec4(0,0,0,0)); * * @brief Images * * @author <NAME> * @date 11/09/2021 * * @param texture The texture. * @param size The size. * @param uv0 (Optional) The uv 0. * @param uv1 (Optional) The first uv. * @param tint_color (Optional) The tint color. * @param border_color (Optional) The border color. */ static void Image(const Ref<Texture2D>& texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_color = ImVec4(1,1,1,1), const ImVec4& border_color = ImVec4(0,0,0,0)); //*********************** Buttons ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::Button(const std::string& label, const ImVec2& size = ImVec2(0,0)); * * @brief Button * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param size (Optional) The size. * * @returns True if it succeeds, false if it fails. */ static bool Button(const std::string& label, const ImVec2& size = ImVec2(0,0)); /** * @fn static bool UI::Button(const char* label, const ImVec2& size = ImVec2(0,0)); * * @brief Buttons * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param size (Optional) The size. * * @returns True if it succeeds, false if it fails. */ static bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); /** * @fn static bool UI::ImageButton(const Ref<Texture2D>& texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_color = ImVec4(0,0,0,0), const ImVec4& tint_color = ImVec4(1,1,1,1)); * * @brief Image button * * @author <NAME> * @date 11/09/2021 * * @param texture The texture. * @param size The size. * @param uv0 (Optional) The uv 0. * @param uv1 (Optional) The first uv. * @param frame_padding (Optional) The frame padding. * @param bg_color (Optional) The background color. * @param tint_color (Optional) The tint color. * * @returns True if it succeeds, false if it fails. */ static bool ImageButton(const Ref<Texture2D>& texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_color = ImVec4(0,0,0,0), const ImVec4& tint_color = ImVec4(1,1,1,1)); //*********************** Misc Begins/Ends + ID/Style/Colors ++++++++++++++++++++++++++++++++// /** * @fn static void UI::BeginDockingWindow(const std::string& label, bool& open, ImGuiWindowFlags flags = 0); * * @brief Begins docking window * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] open True to open. * @param flags (Optional) The flags. */ static void BeginDockingWindow(const std::string& label, bool& open, ImGuiWindowFlags flags = 0); /** * @fn static void UI::EndDockingWindow(); * * @brief Ends docking window * * @author <NAME> * @date 11/09/2021 */ static void EndDockingWindow(); /** * @fn static void UI::BeginWindow(const char* label, bool& open, ImGuiWindowFlags flags = 0); * * @brief Begins a window * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] open True to open. * @param flags (Optional) The flags. */ static void BeginWindow(const char* label, bool& open, ImGuiWindowFlags flags = 0); /** * @fn static void UI::BeginWindow(const std::string& label, bool& open, ImGuiWindowFlags flags = 0); * * @brief Begins a window * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param [in,out] open True to open. * @param flags (Optional) The flags. */ static void BeginWindow(const std::string& label, bool& open, ImGuiWindowFlags flags = 0); /** * @fn static void UI::EndWindow(); * * @brief Ends a window * * @author <NAME> * @date 11/09/2021 */ static void EndWindow(); /** * @fn static void UI::BeginSubWindow(const std::string& label, ImVec2 size, 0} parameter3, bool border, ImGuiWindowFlags flags); * * @brief A sub window of another window. Visibility is controlled by the parent window. * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param size (Optional) The size. * @param border (Optional) True to border. * @param flags (Optional) The flags. */ static void BeginSubWindow(const std::string& label, ImVec2 size = {0,0}, bool border = false, ImGuiWindowFlags flags = 0); /** * @fn static void UI::BeginSubWindow(const char* label, ImVec2 size, 0} parameter3, bool border, ImGuiWindowFlags flags); * * @brief A sub window of another window. Visibility is controlled by the parent window. * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param size (Optional) The size. * @param border (Optional) True to border. * @param flags (Optional) The flags. */ static void BeginSubWindow(const char* label, ImVec2 size = {0,0}, bool border = false, ImGuiWindowFlags flags = 0); /** * @fn static void UI::EndSubWindow(); * * @brief Ends sub window * * @author <NAME> * @date 11/09/2021 */ static void EndSubWindow(); /** * @fn static bool UI::BeginMenuBar(); * * @brief Begins menu bar * * @author <NAME> * @date 11/09/2021 * * @returns True if it succeeds, false if it fails. */ static bool BeginMenuBar(); /** * @fn static void UI::EndMenuBar(); * * @brief Ends menu bar * * @author <NAME> * @date 11/09/2021 */ static void EndMenuBar(); /** * @fn static bool UI::BeginSubMenu(const std::string& label); * * @brief Begins sub menu * * @author <NAME> * @date 11/09/2021 * * @param label The label. * * @returns True if it succeeds, false if it fails. */ static bool BeginSubMenu(const std::string& label); /** * @fn static bool UI::BeginSubMenu(const char* label); * * @brief Begins sub menu * * @author <NAME> * @date 11/09/2021 * * @param label The label. * * @returns True if it succeeds, false if it fails. */ static bool BeginSubMenu(const char* label); /** * @fn static void UI::EndSubMenu(); * * @brief Ends sub menu * * @author <NAME> * @date 11/09/2021 */ static void EndSubMenu(); /** * @fn static bool UI::EntryMenu(const char* label, const char* shortcut = nullptr, bool selected = false, bool enabled = true); * * @brief Entry menu * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param shortcut (Optional) The shortcut. * @param selected (Optional) True if selected. * @param enabled (Optional) True to enable, false to disable. * * @returns True if it succeeds, false if it fails. */ static bool EntryMenu(const char* label, const char* shortcut = nullptr, bool selected = false, bool enabled = true); /** * @fn static bool UI::EntryMenu(const std::string& label, const char* shortcut = nullptr, bool selected = false, bool enabled = true); * * @brief Entry menu * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param shortcut (Optional) The shortcut. * @param selected (Optional) True if selected. * @param enabled (Optional) True to enable, false to disable. * * @returns True if it succeeds, false if it fails. */ static bool EntryMenu(const std::string& label, const char* shortcut = nullptr, bool selected = false, bool enabled = true); /** * @fn static bool UI::EntryMenu(const std::string& label, const std::string& shortcut = "", bool selected = false, bool enabled = true); * * @brief Entry menu * * @author <NAME> * @date 11/09/2021 * * @param label The label. * @param shortcut (Optional) The shortcut. * @param selected (Optional) True if selected. * @param enabled (Optional) True to enable, false to disable. * * @returns True if it succeeds, false if it fails. */ static bool EntryMenu(const std::string& label, const std::string& shortcut = "", bool selected = false, bool enabled = true); /** * @fn static void UI::EntrySeparator(SeparatorStyle style = SeparatorStyle::Line); * * @brief Entry separator * * @author <NAME> * @date 11/09/2021 * * @param style (Optional) The style. */ static void EntrySeparator(SeparatorStyle style = SeparatorStyle::Line); /** * @fn static void UI::EntryLine(LineFlag flag = LineFlag::NextLine); * * @brief Entry line * * @author <NAME> * @date 11/09/2021 * * @param flag (Optional) The flag. */ static void EntryLine(LineFlag flag = LineFlag::NextLine); /** * @fn static void UI::PushID(ImGuiStyleVar id); * * @brief Pushes an identifier * * @author <NAME> * @date 11/09/2021 * * @param id The identifier. */ static void PushID(ImGuiStyleVar id); /** * @fn static void UI::PopID(); * * @brief Pops the identifier * * @author <NAME> * @date 11/09/2021 */ static void PopID(); /** * @fn static void UI::PushStyle(ImGuiStyleVar idx, ImVec2 value); * * @brief Pushes a style * * @author <NAME> * @date 11/09/2021 * * @param idx Zero-based index of the. * @param value The value. */ static void PushStyle(ImGuiStyleVar idx, ImVec2 value); /** * @fn static void UI::PushStyle(ImGuiStyleVar idx, float value); * * @brief Pushes a style * * @author <NAME> * @date 11/09/2021 * * @param idx Zero-based index of the. * @param value The value. */ static void PushStyle(ImGuiStyleVar idx, float value); /** * @fn static void UI::PopStyle(int count = 0); * * @brief Pops the style described by count * * @author <NAME> * @date 11/09/2021 * * @param count (Optional) Number of. */ static void PopStyle(int count = 0); /** * @fn static void UI::PushColor(ImGuiColorEditFlags idx, ImVec4 value); * * @brief Pushes a color * * @author <NAME> * @date 11/09/2021 * * @param idx Zero-based index of the. * @param value The value. */ static void PushColor(ImGuiColorEditFlags idx, ImVec4 value); /** * @fn static void UI::PopColor(int count = 0); * * @brief Pops the color described by count * * @author <NAME> * @date 11/09/2021 * * @param count (Optional) Number of. */ static void PopColor(int count = 0); //*********************** Window Set/Get Properties ++++++++++++++++++++++++++++++++// /** * @fn static bool UI::IsFocused(); * * @brief Query if this object is focused * * @author <NAME> * @date 11/09/2021 * * @returns True if focused, false if not. */ static bool IsFocused(); /** * @fn static void UI::SetWindowPosition(const ImVec2& position = ImVec2(0,0)); * * @brief Sets window position * * @author <NAME> * @date 11/09/2021 * * @param position (Optional) The position. */ static void SetWindowPosition(const ImVec2& position = ImVec2(0,0)); /** * @fn static void UI::SetWindowPosition(const glm::vec2& position = glm::vec2(0,0)); * * @brief Sets window position * * @author <NAME> * @date 11/09/2021 * * @param position (Optional) The position. */ static void SetWindowPosition(const glm::vec2& position = glm::vec2(0,0)); /** * @fn static void UI::SetWindowPosition(const float& x = 0, const float& y = 0); * * @brief Sets window position * * @author <NAME> * @date 11/09/2021 * * @param x (Optional) The x coordinate. * @param y (Optional) The y coordinate. */ static void SetWindowPosition(const float& x = 0, const float& y = 0); /** * @fn static glm::vec2 UI::GetWindowPosition(); * * @brief Gets window position * * @author <NAME> * @date 11/09/2021 * * @returns The window position. */ static glm::vec2 GetWindowPosition(); /** * @fn static glm::vec2 UI::GetWindowMinPosition(); * * @brief Gets the upper left position of the current window * * @author <NAME> * @date 11/09/2021 * * @returns The window minimum position. */ static glm::vec2 GetWindowMinPosition(); /** * @fn static glm::vec2 UI::GetWindowMaxPosition(); * * @brief Gets the bottom right position of the current window * * @author <NAME> * @date 11/09/2021 * * @returns The window maximum position. */ static glm::vec2 GetWindowMaxPosition(); /** * @fn static void UI::SetWindowSize(const ImVec2& size = ImVec2(0,0)); * * @brief Sets window size * * @author <NAME> * @date 11/09/2021 * * @param size (Optional) The size. */ static void SetWindowSize(const ImVec2& size = ImVec2(0,0)); /** * @fn static void UI::SetWindowSize(const glm::vec2& size = glm::vec2(0,0)); * * @brief Sets window size * * @author <NAME> * @date 11/09/2021 * * @param size (Optional) The size. */ static void SetWindowSize(const glm::vec2& size = glm::vec2(0,0)); /** * @fn static void UI::SetWindowSize(const float& x = 0, const float& y = 0); * * @brief Sets window size * * @author <NAME> * @date 11/09/2021 * * @param x (Optional) The x coordinate. * @param y (Optional) The y coordinate. */ static void SetWindowSize(const float& x = 0, const float& y = 0); /** * @fn static glm::vec2 UI::GetWindowSize(); * * @brief Gets window size * * @author <NAME> * @date 11/09/2021 * * @returns The window size. */ static glm::vec2 GetWindowSize(); /** * @fn static void UI::SetCursorPosition(const ImVec2& position = ImVec2(0,0)); * * @brief Sets cursor position * * @author <NAME> * @date 11/09/2021 * * @param position (Optional) The position. */ static void SetCursorPosition(const ImVec2& position = ImVec2(0,0)); /** * @fn static void UI::SetCursorPosition(const glm::vec2& position = glm::vec2(0,0)); * * @brief Sets cursor position * * @author <NAME> * @date 11/09/2021 * * @param position (Optional) The position. */ static void SetCursorPosition(const glm::vec2& position = glm::vec2(0,0)); /** * @fn static void UI::SetCursorPosition(const float& x = 0, const float& y = 0); * * @brief Sets cursor position * * @author <NAME> * @date 11/09/2021 * * @param x (Optional) The x coordinate. * @param y (Optional) The y coordinate. */ static void SetCursorPosition(const float& x = 0, const float& y = 0); /** * @fn static void UI::SetWindowAlpha(const float& alpha = 0); * * @brief Sets window alpha * * @author <NAME> * @date 11/09/2021 * * @param alpha (Optional) The alpha. */ static void SetWindowAlpha(const float& alpha = 0); /** * @fn static void UI::SetWindowBackgroundColor(const ImVec4& bg_color = ImVec4(0,0,0,0)); * * @brief Sets window background color * * @author <NAME> * @date 11/09/2021 * * @param bg_color (Optional) The background color. */ static void SetWindowBackgroundColor(const ImVec4& bg_color = ImVec4(0,0,0,0)); /** * @fn static void UI::SetWindowBackgroundColor(const glm::vec4& bg_color = glm::vec4(0,0,0,0)); * * @brief Sets window background color * * @author <NAME> * @date 11/09/2021 * * @param bg_color (Optional) The background color. */ static void SetWindowBackgroundColor(const glm::vec4& bg_color = glm::vec4(0,0,0,0)); /** * @fn static void UI::SetWindowBackgroundColor(const glm::vec3& bg_color = glm::vec3(0,0,0), const float& alpha = 0); * * @brief Sets window background color * * @author <NAME> * @date 11/09/2021 * * @param bg_color (Optional) The background color. * @param alpha (Optional) The alpha. */ static void SetWindowBackgroundColor(const glm::vec3& bg_color = glm::vec3(0,0,0), const float& alpha = 0); /** * @fn static void UI::SetWindowRounding(const float& value); * * @brief Sets window rounding * * @author <NAME> * @date 11/09/2021 * * @param value The value. */ static void SetWindowRounding(const float& value); /** * @fn static void UI::SetWindowPadding(const ImVec2& value); * * @brief Sets window padding * * @author <NAME> * @date 11/09/2021 * * @param value The value. */ static void SetWindowPadding(const ImVec2& value); /** * @fn static void UI::SetWindowPadding(const glm::vec2& value); * * @brief Sets window padding * * @author <NAME> * @date 11/09/2021 * * @param value The value. */ static void SetWindowPadding(const glm::vec2& value); /** * @fn static void UI::ClearWindowRounding(); * * @brief Clears the window rounding * * @author <NAME> * @date 11/09/2021 */ static void ClearWindowRounding(); /** * @fn static void UI::ClearWindowPadding(); * * @brief Clears the window padding * * @author <NAME> * @date 11/09/2021 */ static void ClearWindowPadding(); /** * @fn static glm::vec2 UI::GetContentSpaceAvailable(); * * @brief Gets content space available * * @author <NAME> * @date 11/09/2021 * * @returns The content space available. */ static glm::vec2 GetContentSpaceAvailable(); //*********************** Button Set Properties ++++++++++++++++++++++++++++++++// /** * @fn static void UI::SetButtonColors(const ImVec4& idleColor, const ImVec4& hoverColor, const ImVec4& pressedColor); * * @brief Sets idle, hover and pressed colors for a button. * @warning Clear with UI::ClearButtonColors() * * @author <NAME> * @date 11/09/2021 * * @param idleColor The idle color. * @param hoverColor The hover color. * @param pressedColor The pressed color. */ static void SetButtonColors(const ImVec4& idleColor, const ImVec4& hoverColor, const ImVec4& pressedColor); /** * @fn static void UI::SetButtonColors(const glm::vec4& idleColor, const glm::vec4& hoverColor, const glm::vec4& pressedColor); * * @brief Sets button colors * * @author <NAME> * @date 11/09/2021 * * @param idleColor The idle color. * @param hoverColor The hover color. * @param pressedColor The pressed color. */ static void SetButtonColors(const glm::vec4& idleColor, const glm::vec4& hoverColor, const glm::vec4& pressedColor); /** * @fn static void UI::SetButtonStateColor(const ImVec4& color, ImGuiCol buttonState = ImGuiCol_Button); * * @brief Sets a given state color for a button * @warning Clear with UI::ClearButtonColor() * * @author <NAME> * @date 11/09/2021 * * @param color The color. * @param buttonState (Optional) State of the button. */ static void SetButtonStateColor(const ImVec4& color, ImGuiCol buttonState = ImGuiCol_Button); /** * @fn static void UI::SetButtonStateColor(const glm::vec4& color, ImGuiCol buttonState = ImGuiCol_Button); * * @brief Sets button state color * * @author <NAME> * @date 11/09/2021 * * @param color The color. * @param buttonState (Optional) State of the button. */ static void SetButtonStateColor(const glm::vec4& color, ImGuiCol buttonState = ImGuiCol_Button); /** * @fn static void UI::SetButtonIdleColor(const ImVec4& color); * * @brief Sets a single state color for a button * @warning Clear with UI::ClearButtonXXXColor() where XXX is the state set * * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonIdleColor(const ImVec4& color); /** * @fn static void UI::SetButtonIdleColor(const glm::vec4& color); * * @brief Sets button idle color * @warning Clear with UI::ClearButtonXXXColor() where XXX is the state set * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonIdleColor(const glm::vec4& color); /** * @fn static void UI::SetButtonHoverColor(const ImVec4& color); * * @brief Sets button hover color * * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonHoverColor(const ImVec4& color); /** * @fn static void UI::SetButtonHoverColor(const glm::vec4& color); * * @brief Sets button hover color * @warning Clear with UI::ClearButtonXXXColor() where XXX is the state set * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonHoverColor(const glm::vec4& color); /** * @fn static void UI::SetButtonPressedColor(const ImVec4& color); * * @brief Sets button pressed color * @warning Clear with UI::ClearButtonXXXColor() where XXX is the state set * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonPressedColor(const ImVec4& color); /** * @fn static void UI::SetButtonPressedColor(const glm::vec4& color); * * @brief Sets button pressed color * @warning Clear with UI::ClearButtonXXXColor() where XXX is the state set * @author <NAME> * @date 11/09/2021 * * @param color The color. */ static void SetButtonPressedColor(const glm::vec4& color); /** * @fn static void UI::ClearButtonIdleColor(); * * @brief Clear a buttons idle color * * @author <NAME> * @date 11/09/2021 */ static void ClearButtonIdleColor(); /** * @fn static void UI::ClearButtonHoverColor(); * * @brief Clear a buttons hover color * * @author <NAME> * @date 11/09/2021 */ static void ClearButtonHoverColor(); /** * @fn static void UI::ClearButtonPressedColor(); * * @brief Clear a buttons pressed color * * @author <NAME> * @date 11/09/2021 */ static void ClearButtonPressedColor(); /** * @fn static void UI::ClearButtonColors(); * * @brief Clear a button from all colors set * * @author <NAME> * @date 11/09/2021 */ static void ClearButtonColors(); /** * @fn static void UI::ClearButtonColor(); * * @brief Clear a single buttons color style * * @author <NAME> * @date 11/09/2021 */ static void ClearButtonColor(); //*********************** Fonts ++++++++++++++++++++++++++++++++// /** * @fn static void UI::SetFont(ImFont* font); * * @brief Sets a font * * @author <NAME> * @date 11/09/2021 * * @param [in,out] font If non-null, the font. */ static void SetFont(ImFont* font); /** * @fn static ImFont* UI::LoadFont(const char* fontPath, float size_pixels); * * @brief Loads a font * * @author <NAME> * @date 11/09/2021 * * @param fontPath Full pathname of the font file. * @param size_pixels The size pixels. * * @returns Null if it fails, else the font. */ static ImFont* LoadFont(const char* fontPath, float size_pixels); /** * @fn static void UI::LoadFonts(const char* rootFontPath, float size_pixels); * * @brief Loads the fonts * * @author <NAME> * @date 11/09/2021 * * @param rootFontPath Full pathname of the root font file. * @param size_pixels The size pixels. */ static void LoadFonts(const char* rootFontPath, float size_pixels); /** * @fn static ImFont* UI::LoadFont(const std::string& fontPath, float size_pixels); * * @brief Loads a font * * @author <NAME> * @date 11/09/2021 * * @param fontPath Full pathname of the font file. * @param size_pixels The size pixels. * * @returns Null if it fails, else the font. */ static ImFont* LoadFont(const std::string& fontPath, float size_pixels); /** * @fn static void UI::LoadFonts(const std::string& rootFontPath, float size_pixels); * * @brief Loads the fonts * * @author <NAME> * @date 11/09/2021 * * @param rootFontPath Full pathname of the root font file. * @param size_pixels The size pixels. */ static void LoadFonts(const std::string& rootFontPath, float size_pixels); /** * @fn static std::vector<ImFont*> UI::LoadFonts(const std::vector<std::string>& fontPaths, float size_pixels); * * @brief Loads the fonts * * @author <NAME> * @date 11/09/2021 * * @param fontPaths The font paths. * @param size_pixels The size pixels. * * @returns Null if it fails, else the fonts. */ static std::vector<ImFont*> LoadFonts(const std::vector<std::string>& fontPaths, float size_pixels); /** * @fn static std::list<ImFont*> UI::LoadFonts(const std::list<std::string>& fontPaths, float size_pixels); * * @brief Loads the fonts * * @author <NAME> * @date 11/09/2021 * * @param fontPaths The font paths. * @param size_pixels The size pixels. * * @returns Null if it fails, else the fonts. */ static std::list<ImFont*> LoadFonts(const std::list<std::string>& fontPaths, float size_pixels); /** * @fn static void UI::SetDefaultFont(const char* fontPath, float size_pixels); * * @brief Sets default font * * @author <NAME> * @date 11/09/2021 * * @param fontPath Full pathname of the font file. * @param size_pixels The size pixels. */ static void SetDefaultFont(const char* fontPath, float size_pixels); /** * @fn static void UI::SetDefaultFont(ImFont* font); * * @brief Sets default font * * @author <NAME> * @date 11/09/2021 * * @param [in,out] font If non-null, the font. */ static void SetDefaultFont(ImFont* font); //*********************** Misc Widgets ++++++++++++++++++++++++++++++++// /** * @fn static std::string UI::OpenFileBrowser(const char* browserLabel, const FileBrowserMode& mode = FileBrowserMode::Open, const ImVec2& position = ImVec2(0,0), const char* validTypes = "*.*"); * * @brief Opens file browser * * @author <NAME> * @date 11/09/2021 * * @param browserLabel The browser label. * @param mode (Optional) The mode. * @param position (Optional) The position. * @param validTypes (Optional) List of types of the valids. * * @returns A std::string. */ static std::string OpenFileBrowser(const char* browserLabel, const FileBrowserMode& mode = FileBrowserMode::Open, const ImVec2& position = ImVec2(0,0), const char* validTypes = "*.*"); /** * @fn static void UI::EntryToggleCheckbox(const char* id, bool& value); * * @brief Entry toggle checkbox * * @author <NAME> * @date 11/09/2021 * * @param id The identifier. * @param [in,out] value True to value. */ static void EntryToggleCheckbox(const char* id, bool& value); //TODO: Add functions for the spinners and loading widgets private: //*********************** Control Variables ++++++++++++++++++++++++++++++++// /** @brief The counter */ inline static uint32_t s_Counter = 0; /** * @property inline static char s_IDBuffer[16] * * @brief Gets the identifier buffer[ 16] * * @returns The s identifier buffer[ 16]. */ inline static char s_IDBuffer[16]; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/AIComponent.h
/*****************************************************************//** * @file AIComponent.h * @brief Holds the AI information * * @author chris * @date November 2021 *********************************************************************/ #pragma once # define PI 3.14159265358979323846 #include "AStar.h" #include "Character.h" #include "TNAH/Core/Timestep.h" namespace tnah { inline double randFloat() { return ((rand()) / (RAND_MAX + 1.0)); } inline double randomClamped() { return randFloat() - randFloat(); } class AIComponent { public: AIComponent() { m_Velocity = glm::vec3(1, 0 , 1); currentlyWandering = true; } ~AIComponent() { } /** * * @fn GetTargetPosition * @brief * * @return * @author chris */ const glm::vec3& GetTargetPosition() const; /** * * @fn SetTargetPosition * @brief * * @param targetPosition * @author chris */ void SetTargetPosition(const glm::vec3& targetPosition); /** * * @fn TargetCutoffDistance * @brief * * @return * @author chris */ float TargetCutoffDistance() const; /** * * @fn SetTargetCutoffDistance * @brief * * @param targetCutoffDistance * @author chris */ void SetTargetCutoffDistance(float targetCutoffDistance); /** * * @fn MovementSpeed * @brief * * @return * @author chris */ float MovementSpeed() const; /** * * @fn SetMovementSpeed * @brief * * @param movementSpeed * @author chris */ void SetMovementSpeed(float movementSpeed); /** * * @fn MovementAllowed * @brief * * @return * @author chris */ bool MovementAllowed() const; /** * * @fn SetMovementAllowed * @brief * * @param movementAllowed * @author chris */ void SetMovementAllowed(bool movementAllowed); /** * * @fn SetVelocity * @brief * * @param vel * @author chris */ void SetVelocity(const glm::vec3 vel) { m_Velocity = vel; } /** * * @fn SetWander * @brief * * @param w * @author chris */ void SetWander(bool w) {currentlyWandering = w;} /** * * @fn GetWander * @brief * * @return * @author chris */ bool GetWander() const {return currentlyWandering;} /** * * @fn OnUpdate * @brief Updates the ai compoennt sorting out wanders ect * * @param deltaTime * @param trans * @author chris */ void OnUpdate(Timestep deltaTime, TransformComponent &trans); /** * * @fn GetPositions * @brief * * @return * @author chris */ std::deque<Node> GetPositions() {return currentPath;} private: /** * * @fn moveTo * @brief Moves to the given location * * @param curPos * @param targetPos * @param curVelocity * @param time * @param rot * @return * @author chris */ bool moveTo(glm::vec3& curPos, const glm::vec3& targetPos, glm::vec3& curVelocity, float time, glm::vec3& rot); private: /** Target position of the object */ glm::vec3 m_TargetPosition = {}; /** cuttoff distance */ float m_TargetCutoffDistance = 1.0f; /** Movement speed */ float m_MovementSpeed = 1.0f; /** if it is allowed to move */ bool m_MovementAllowed = true; /** The current velocity */ glm::vec3 m_Velocity = {}; /** if it is current wandering */ bool currentlyWandering; //AStar stuff /** The current position*/ Node currentPosition; /** The current destination*/ Node destination; /** The current path*/ std::deque<Node> currentPath = {}; inline static std::string s_SearchString = "AiCharacter Component"; /** @brief Type identifiers for the component */ inline static ComponentTypes s_Types = { {ComponentVariations::AiCharacter}, {{ComponentCategory::Physics}} }; friend class EditorUI; }; inline const glm::vec3& AIComponent::GetTargetPosition() const { return m_TargetPosition; } inline void AIComponent::SetTargetPosition(const glm::vec3& targetPosition) { m_TargetPosition = targetPosition; } inline float AIComponent::TargetCutoffDistance() const { return m_TargetCutoffDistance; } inline void AIComponent::SetTargetCutoffDistance(float targetCutoffDistance) { m_TargetCutoffDistance = targetCutoffDistance; } inline float AIComponent::MovementSpeed() const { return m_MovementSpeed; } inline void AIComponent::SetMovementSpeed(float movementSpeed) { m_MovementSpeed = movementSpeed; } inline bool AIComponent::MovementAllowed() const { return m_MovementAllowed; } inline void AIComponent::SetMovementAllowed(bool movementAllowed) { m_MovementAllowed = movementAllowed; } }
BryceStandley/TNAH
core/src/TNAH/Core/UUID.h
<gh_stars>1-10 #pragma once #include "Core.h" #include <xhash> namespace tnah { /** * @class UUID * * @brief An unique identifer class used for gameobjects * * @author <NAME> * @date 7/09/2021 */ class UUID { public: /** * @fn UUID::UUID(); * * @brief Default constructor * * @author <NAME> * @date 7/09/2021 */ UUID(); /** * @fn UUID::UUID(uint64_t uuid); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param uuid The uuid. */ UUID(uint64_t uuid); /** * @fn UUID::UUID(const UUID& other); * * @brief Copy constructor * * @author <NAME> * @date 7/09/2021 * * @param other The other. */ UUID(const UUID& other); /** * @fn operator UUID::uint64_t () * * @brief Cast that converts the given to a uint64_t * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator uint64_t () { return m_UUID; } /** * @fn operator const UUID::uint64_t() const * * @brief Cast that converts the given to a const uint64_t * * @author <NAME> * @date 7/09/2021 * * @returns A const. */ operator const uint64_t() const { return m_UUID; } private: /** @brief The uuid */ uint64_t m_UUID; }; } namespace std { template <> /** * @struct hash<tnah::UUID> * * @brief A templated hash that used the uuid * * @author <NAME> * @date 7/09/2021 */ struct hash<tnah::UUID> { /** * @fn std::size_t operator()(const tnah::UUID& uuid) const * * @brief Function call operator * * @author <NAME> * @date 7/09/2021 * * @param uuid The uuid. * * @returns The result of the operation. */ std::size_t operator()(const tnah::UUID& uuid) const { return hash<uint64_t>()((uint64_t)uuid); } }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/VertexArray.h
#pragma once #include <memory> #include "TNAH/Renderer/RenderingBuffers.h" namespace tnah { /** * @class VertexArray * * @brief VertexArray class that allows for the setup of a VAO * * @author <NAME> * @date 12/09/2021 */ class VertexArray : public RefCounted { public: /** * @fn virtual VertexArray::~VertexArray() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~VertexArray() = default; /** * @fn virtual void VertexArray::Bind() const = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() const = 0; /** * @fn virtual void VertexArray::Unbind() const = 0; * * @brief Unbinds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Unbind() const = 0; /** * @fn virtual void VertexArray::SetID(const uint32_t& id) = 0; * * @brief Sets an identifier * * @author <NAME> * @date 12/09/2021 * * @param id The identifier. */ virtual void SetID(const uint32_t& id) = 0; /** * @fn virtual void VertexArray::AddVertexBuffer(const Ref<VertexBuffer>& vertexBuffer) = 0; * * @brief Adds a vertex buffer * * @author <NAME> * @date 12/09/2021 * * @param vertexBuffer Buffer for vertex data. */ virtual void AddVertexBuffer(const Ref<VertexBuffer>& vertexBuffer) = 0; /** * @fn virtual void VertexArray::SetIndexBuffer(const Ref<IndexBuffer>& indexBuffer) = 0; * * @brief Sets index buffer * * @author <NAME> * @date 12/09/2021 * * @param indexBuffer Buffer for index data. */ virtual void UpdateVertexBuffer() = 0; virtual void SetIndexBuffer(const Ref<IndexBuffer>& indexBuffer) = 0; /** * @fn virtual void VertexArray::SetIndexSize(const uint32_t& size) = 0; * * @brief Sets index size * * @author <NAME> * @date 12/09/2021 * * @param size The size. */ virtual void SetIndexSize(const uint32_t& size) = 0; /** * @fn virtual const std::vector<Ref<VertexBuffer>>& VertexArray::GetVertexBuffers() const = 0; * * @brief Gets vertex buffers * * @author <NAME> * @date 12/09/2021 * * @returns The vertex buffers. */ virtual const std::vector<Ref<VertexBuffer>>& GetVertexBuffers() const = 0; /** * @fn virtual const Ref<IndexBuffer>& VertexArray::GetIndexBuffer() const = 0; * * @brief Gets index buffer * * @author <NAME> * @date 12/09/2021 * * @returns The index buffer. */ virtual const Ref<IndexBuffer>& GetIndexBuffer() const = 0; /** * @fn virtual uint32_t VertexArray::GetIndexSize() const = 0; * * @brief Gets index size * * @author <NAME> * @date 12/09/2021 * * @returns The index size. */ virtual uint32_t GetIndexSize() const = 0; /** * @fn static VertexArray* VertexArray::Create(); * * @brief Creates a new VertexArray and binds it for use * * @author <NAME> * @date 12/09/2021 * * @returns Null if it fails, else a pointer to a VertexArray. */ static VertexArray* Create(); /** @brief Size of the indices */ uint32_t m_IndicesSize; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Timestep.h
<filename>core/src/TNAH/Core/Timestep.h #pragma once namespace tnah { /** * @class Timestep * * @brief A timestep class that handles the time * * @author <NAME> * @date 7/09/2021 */ class Timestep { public: /** * @fn Timestep::Timestep(float time = 0.0f) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param time (Optional) The time. */ Timestep(float time = 0.0f) : m_Time(time) { } /** * @fn operator Timestep::float() const * * @brief Cast that converts the given to a float * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator float() const { return m_Time; } /** * @fn float Timestep::GetSeconds() const * * @brief Gets the seconds * * @author <NAME> * @date 7/09/2021 * * @returns The seconds. */ float GetSeconds() const { return m_Time; } /** * @fn float Timestep::GetMilliseconds() const * * @brief Gets the milliseconds of time * * @author <NAME> * @date 7/09/2021 * * @returns The milliseconds. */ float GetMilliseconds() const { return m_Time * 1000.0f; } private: float m_Time; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/ComponentIdentification.h
<filename>core/src/TNAH/Scene/Components/ComponentIdentification.h #pragma once namespace tnah { /**********************************************************************************************//** * @enum ComponentVariations * * @brief Values that represent component types **************************************************************************************************/ enum class ComponentVariations { None, ID, Tag, Relationship, Transform, NativeScript, CSharpScript, Camera, EditorCamera, Editor, Skybox, Light, Terrain, Mesh, PlayerController, AudioSource, AudioListener, Rigidbody, AiCharacter, AStar, AStarObstacle, Affordance }; /**********************************************************************************************//** * @enum ComponentCategory * * @brief Values that represent the base type of a component and what category they belong to. **************************************************************************************************/ enum class ComponentCategory { Core, Editor, Camera, Lighting, Controls, Audio, Physics, Rendering, Environment, Objects, Script, AI, Emotion, Custom }; /**********************************************************************************************//** * @struct ComponentTypes * * @brief Structure of a component identification. Used to find and list components within the editor **************************************************************************************************/ struct ComponentTypes { ComponentVariations Component; std::list<ComponentCategory> Categories; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/Affordance.h
/*****************************************************************//** * @file Affordance.h * @brief Affordances * * @author chris * @date November 2021 *********************************************************************/ #pragma once #include "Actions.h" #include <unordered_map> namespace tnah { class Affordance { public: Affordance(std::string t = ""); ~Affordance(); /** * * @fn GetActionValue * @brief Gets the value of the givena action * * @param action * @return float * @author chris */ float GetActionValue(Actions action); /** * * @fn SetActionValues * @brief Sets the action to the given value * * @param action * @param value * @author chris */ void SetActionValues(Actions action, float value); /** * * @fn GetTag * * @return * @author chris */ std::string GetTag() const {return tag;} /** * * @fn GetActionString * @brief Gets the action string * * @param action * @return * @author chris */ static std::string GetActionString(Actions action); /** * * @fn GetActions * * @author chris */ std::unordered_map<Actions, float> GetActions() {return objectsActions;}; ///Editor value float editorValue = 0; ///Most recent std::string recent = ""; private: ///The tag std::string tag; ///The objects actions std::unordered_map<Actions, float> objectsActions; inline static std::string s_SearchString = "Affordance"; /** @brief Type identifiers for the component */ inline static ComponentTypes s_Types = { {ComponentVariations::Affordance}, {{ComponentCategory::AI},{ComponentCategory::Emotion}} }; friend class EditorUI; }; }
BryceStandley/TNAH
core/src/TNAH/Core/AABB.h
<filename>core/src/TNAH/Core/AABB.h #pragma once #include <glm/glm.hpp> namespace tnah { /** * @struct AABB * * @brief An aabb bounding box * * @author <NAME> * @date 7/09/2021 */ struct AABB { /** @brief The minimum value and maximum value */ glm::vec3 Min, Max; /** * @fn AABB() * * @brief Default constructor * * @author <NAME> * @date 7/09/2021 */ AABB() : Min(0.0f), Max(0.0f) {} /** * @fn AABB(const glm::vec3& min, const glm::vec3& max) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param min The minimum. * @param max The maximum. */ AABB(const glm::vec3& min, const glm::vec3& max) : Min(min), Max(max) {} }; }
BryceStandley/TNAH
core/src/Platform/OpenGL/OpenGLTexture.h
<filename>core/src/Platform/OpenGL/OpenGLTexture.h #pragma once #include "TNAH/Renderer/Texture.h" #include <glad/glad.h> namespace tnah { /** * @class OpenGLTexture2D * * @brief An OpenGLTexture2D class that inherits from the Texture2D class * * @author <NAME> * @date 7/09/2021 */ class OpenGLTexture2D : public Texture2D { public: /** * @fn OpenGLTexture2D::OpenGLTexture2D(ImageFormat format, uint32_t width, uint32_t height, const void* data, TextureProperties properties); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param format Describes the image format to use. * @param width The width. * @param height The height. * @param data The data. * @param properties The properties. */ OpenGLTexture2D(ImageFormat format, uint32_t width, uint32_t height, const void* data, TextureProperties properties); /** * @fn OpenGLTexture2D::OpenGLTexture2D(uint32_t width, uint32_t height); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param width The width. * @param height The height. */ OpenGLTexture2D(uint32_t width, uint32_t height); /** * @fn OpenGLTexture2D::OpenGLTexture2D(const std::string& path, const std::string& textureName = "", bool loadFromMemory = false, void* assimpTexture = nullptr); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param path Full pathname of the file. * @param textureName (Optional) Name of the texture. * @param loadFromMemory (Optional) True to load from memory. * @param [in,out] assimpTexture (Optional) If non-null, the assimp texture. */ OpenGLTexture2D(const std::string& path, const std::string& textureName = "", bool loadFromMemory = false, void* assimpTexture = nullptr); /** * @fn OpenGLTexture2D::~OpenGLTexture2D() override; * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ ~OpenGLTexture2D() override; /** * @fn unsigned char* OpenGLTexture2D::LoadFromMemory(const std::string& path, void* assimpTexture = nullptr); * * @brief Loads from memory * * @author <NAME> * @date 7/09/2021 * * @param path Full pathname of the file. * @param [in,out] assimpTexture (Optional) If non-null, the assimp texture. * * @returns Null if it fails, else the data that was read from the memory. */ unsigned char* LoadFromMemory(const std::string& path, void* assimpTexture = nullptr); /** * @fn uint32_t OpenGLTexture2D::GetWidth() const override * * @brief Gets the width * * @author <NAME> * @date 7/09/2021 * * @returns The width. */ uint32_t GetWidth() const override { return m_Width; } /** * @fn uint32_t OpenGLTexture2D::GetHeight() const override * * @brief Gets the height * * @author <NAME> * @date 7/09/2021 * * @returns The height. */ uint32_t GetHeight() const override { return m_Height; } /** * @fn uint32_t OpenGLTexture2D::GetRendererID() const override * * @brief Gets renderer identifier * * @author <NAME> * @date 7/09/2021 * * @returns The renderer identifier. */ uint32_t GetRendererID() const override { return m_RendererID; } /** * @fn void OpenGLTexture2D::SetData(void* data, uint32_t size) override; * * @brief Sets the data * * @author <NAME> * @date 7/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ void SetData(void* data, uint32_t size) override; /** * @fn void OpenGLTexture2D::Bind(uint32_t slot) const override; * * @brief Binds the given slot * * @author <NAME> * @date 7/09/2021 * * @param slot The slot. */ void Bind(uint32_t slot) const override; /** * @fn void OpenGLTexture2D::Bind() const override; * * @brief Binds this object * * @author <NAME> * @date 7/09/2021 */ void Bind() const override; /** * @fn ktxTexture* OpenGLTexture2D::GetKtxData() const override * * @brief Gets ktx data * * @author <NAME> * @date 7/09/2021 * * @returns Null if it fails, else the ktx data. */ ktxTexture* GetKtxData() const override { return nullptr; } /** * @fn unsigned char* OpenGLTexture2D::GetImageData() const override * * @brief Gets image data * * @author <NAME> * @date 7/09/2021 * * @returns Null if it fails, else the image data. */ unsigned char* GetImageData() const override { return nullptr; } /** * @fn void OpenGLTexture2D::Free() override * * @brief Frees this object * * @author <NAME> * @date 7/09/2021 */ void Free() override {} /** * @fn void OpenGLTexture2D::Free(void* data) override * * @brief Frees the given data * * @author <NAME> * @date 7/09/2021 * * @param [in,out] data If non-null, the data. */ void Free(void* data) override {} }; /** * @class OpenGLTexture3D * * @brief An OpenGLTexture3D that inherits from the base glass Texture3D * * @author <NAME> * @date 7/09/2021 */ class OpenGLTexture3D : public Texture3D { public: /** * @fn OpenGLTexture3D::OpenGLTexture3D(const std::vector<std::string>& paths, const std::string& textureName = ""); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param paths A vector of texture paths. * @param textureName (Optional) Name of the texture. */ OpenGLTexture3D(const std::vector<std::string>& paths, const std::string& textureName = ""); /** * @fn OpenGLTexture3D::OpenGLTexture3D(const Texture3DProperties& properties, const std::string& textureName = ""); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param properties The properties. * @param textureName (Optional) Name of the texture. */ OpenGLTexture3D(const Texture3DProperties& properties, const std::string& textureName = ""); /** * @fn OpenGLTexture3D::~OpenGLTexture3D() override; * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ ~OpenGLTexture3D() override; /** * @fn uint32_t OpenGLTexture3D::GetWidth() const override * * @brief Gets the width * * @author <NAME> * @date 7/09/2021 * * @returns The width. */ uint32_t GetWidth() const override { return m_Width; } /** * @fn uint32_t OpenGLTexture3D::GetHeight() const override * * @brief Gets the height * * @author <NAME> * @date 7/09/2021 * * @returns The height. */ uint32_t GetHeight() const override { return m_Height; } /** * @fn uint32_t OpenGLTexture3D::GetRendererID() const override * * @brief Gets renderer identifier * * @author <NAME> * @date 7/09/2021 * * @returns The renderer identifier. */ uint32_t GetRendererID() const override { return m_RendererID; } /** * @fn void OpenGLTexture3D::SetData(void* data, uint32_t size) override; * * @brief Sets a data * * @author <NAME> * @date 7/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ void SetData(void* data, uint32_t size) override; /** * @fn void OpenGLTexture3D::Bind(uint32_t slot) const override; * * @brief Binds the given slot * * @author <NAME> * @date 7/09/2021 * * @param slot The slot. */ void Bind(uint32_t slot) const override; /** * @fn void OpenGLTexture3D::Bind() const override; * * @brief Binds this object * * @author <NAME> * @date 7/09/2021 */ void Bind() const override; /** * @fn ktxTexture* OpenGLTexture3D::GetKtxData() const override * * @brief Gets ktx data * * @author <NAME> * @date 7/09/2021 * * @returns nullptr. */ ktxTexture* GetKtxData() const override { return nullptr; } /** * @fn unsigned char* OpenGLTexture3D::GetImageData() const override * * @brief Gets image data * * @author <NAME> * @date 7/09/2021 * * @returns nullptr. */ unsigned char* GetImageData() const override { return nullptr; } }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/PlayerInteractions.h
/*****************************************************************//** * @file PlayerInteractions.h * @brief * * @author chris * @date November 2021 *********************************************************************/ #pragma once namespace tnah { struct PlayerInteractions { PlayerInteractions() : distance(3.0f) {} float distance; }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Texture.h
#pragma once #pragma warning(push, 0) #include <string> #include <ktx.h> #pragma warning(pop) #include "TNAH/Core/Core.h" #include "TNAH/Core/FileStructures.h" #include "TNAH/Core/Ref.h" namespace tnah { #pragma region Enums using uchar8_t = unsigned char; /** * @enum ImageLoadFormat * * @brief Values that represent image load formats */ enum class ImageLoadFormat { KTX, STB }; /** * @enum ImageFormat * * @brief Values that represent image formats */ enum class ImageFormat { None = 0, RED32F, RGB, RGBA, RGBA16F, RGBA32F, RG16F, RG32F, SRGB, DEPTH32F, DEPTH24STENCIL8, // Defaults Depth = DEPTH24STENCIL8, }; /** * @enum ImageUsage * * @brief Values that represent image usage options */ enum class ImageUsage { None = 0, Texture, Attachment, Storage }; /** * @enum TextureWrap * * @brief Values that represent texture wrap options */ enum class TextureWrap { None = 0, Clamp, Repeat }; /** * @enum TextureFilter * * @brief Values that represent texture filter options */ enum class TextureFilter { None = 0, Linear, Nearest }; /** * @enum TextureType * * @brief Values that represent texture types */ enum class TextureType { None = 0, Texture2D, Texture3D }; /** * @struct TextureProperties * * @brief texture properties. * * @author <NAME> * @date 12/09/2021 */ struct TextureProperties { /** @brief The sampler wrap */ TextureWrap SamplerWrap = TextureWrap::Repeat; /** @brief A filter specifying the sampler */ TextureFilter SamplerFilter = TextureFilter::Linear; /** @brief True to generate mips */ bool GenerateMips = true; /** @brief True to sRGB */ bool SRGB = false; /** @brief True to storage */ bool Storage = false; }; /** * @struct ImageSpecification * * @brief An image specification struct * * @author <NAME> * @date 12/09/2021 */ struct ImageSpecification { /** @brief Describes the format to use */ ImageFormat Format = ImageFormat::RGBA; /** @brief The usage */ ImageUsage Usage = ImageUsage::Texture; /** @brief The width */ uint32_t Width = 1; /** @brief The height */ uint32_t Height = 1; /** @brief The mips */ uint32_t Mips = 1; /** @brief The layers */ uint32_t Layers = 1; /** @brief True if deinterleaved */ bool Deinterleaved = false; /** @brief Name of the debug */ std::string DebugName = ""; }; /** * @class Texture3DProperties * * @brief A texture 3D properties class. Used to assist with skybox creation * * @author <NAME> * @date 12/09/2021 */ class Texture3DProperties { public: /** * @fn Texture3DProperties::Texture3DProperties() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 12/09/2021 */ Texture3DProperties() = default; /** * @fn Texture3DProperties::Texture3DProperties(Resource front,Resource back, Resource left, Resource right, Resource top, Resource bottom) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param front The front. * @param back The back. * @param left The left. * @param right The right. * @param top The top. * @param bottom The bottom. */ Texture3DProperties(Resource front,Resource back, Resource left, Resource right, Resource top, Resource bottom) :Front(front), Back(back), Left(left), Right(right), Top(top), Bottom(bottom) {} /** * @fn Texture3DProperties::Texture3DProperties(Resource cubemap) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param cubemap The cubemap. */ Texture3DProperties(Resource cubemap) :Cubemap(cubemap) { if(Cubemap.Type.Type == RType::Image && Cubemap.FileName.Extension.find("ktx") != std::string::npos) { IsKtx = true; } } /** @brief The cubemap */ Resource Cubemap; /** @brief True if is ktx, false if not */ bool IsKtx = false; /** @brief The front face */ Resource Front; /** @brief The back face */ Resource Back; /** @brief The left face */ Resource Left; /** @brief The right face */ Resource Right; /** @brief The top face */ Resource Top; /** @brief The bottom face */ Resource Bottom; }; /** * @enum CubemapImageFormat * * @brief Values that represent cubemap image formats */ enum class CubemapImageFormat { Column, Row, Vertical, Horizontal }; /** * @struct CubemapInformation * * @brief Information about the cubemap. * * @author <NAME> * @date 12/09/2021 */ struct CubemapInformation { uint32_t CubeSize = 1; CubemapImageFormat Format = CubemapImageFormat::Column; }; /** * @class Texture * * @brief A texture class responsible for loading and applying textures * * @author <NAME> * @date 12/09/2021 */ #pragma endregion class Texture : public RefCounted { public: /** * @fn virtual Texture::~Texture() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Texture() = default; /** * @fn virtual uint32_t Texture::GetWidth() const * * @brief Gets the width * * @author <NAME> * @date 12/09/2021 * * @returns The width. */ virtual uint32_t GetWidth() const { return m_Width; } /** * @fn virtual uint32_t Texture::GetHeight() const * * @brief Gets the height * * @author <NAME> * @date 12/09/2021 * * @returns The height. */ virtual uint32_t GetHeight() const { return m_Height; } /** * @fn virtual bool Texture::IsLoaded() const * * @brief Query if this object is loaded * * @author <NAME> * @date 12/09/2021 * * @returns True if loaded, false if not. */ virtual bool IsLoaded() const { return m_Loaded; } /** * @fn virtual std::string Texture::GetPath() const * * @brief Gets the path * * @author <NAME> * @date 12/09/2021 * * @returns The path. */ virtual std::string GetPath() const { return m_TextureResource.RelativeDirectory; } /** * @fn virtual std::string Texture::GetName() const * * @brief Gets the name * * @author <NAME> * @date 12/09/2021 * * @returns The name. */ virtual std::string GetName() const { return m_TextureResource.FileName.FileName; } /** * @fn virtual ImageLoadFormat Texture::GetLoadFormat() const * * @brief Gets load format * * @author <NAME> * @date 12/09/2021 * * @returns The load format. */ virtual ImageLoadFormat GetLoadFormat() const { return m_LoadFormat; } /** * @fn virtual ktxTexture* Texture::GetKtxData() const = 0; * * @brief Returns a KTX Texture or nullptr if invalid * * @author <NAME> * @date 12/09/2021 * * @returns Null if it fails, else the ktx data. */ virtual ktxTexture* GetKtxData() const = 0; /** * @fn virtual uchar8_t* Texture::GetImageData() const = 0; * * @brief Returns a uchar8_t of image data or nullptr if invalid * * @author <NAME> * @date 12/09/2021 * * @returns Null if it fails, else the image data. */ virtual uchar8_t* GetImageData() const = 0; std::string m_UniformName = ""; Resource m_TextureResource; /** @brief True if the data was loaded */ bool m_Loaded = false; /** @brief The height and width */ uint32_t m_Width = 0, m_Height = 0; /** @brief The channels, internal format, and data format */ uint32_t m_Channels = 0, m_InternalFormat = 0, m_DataFormat = 0; /** @brief Information describing the image */ void* m_ImageData = nullptr; /** @brief The load format */ ImageLoadFormat m_LoadFormat = ImageLoadFormat::STB; /** @brief The properties */ TextureProperties m_Properties = TextureProperties(); /** @brief Information describing the cubemap */ CubemapInformation m_CubemapInformation = CubemapInformation(); }; /** * @class Texture2D * * @brief A texture 2d class that inherits from the Texture class. Handles 2D textures * * @author <NAME> * @date 12/09/2021 */ class Texture2D : public Texture { public: /** * @fn static Ref<Texture2D> Texture2D::Create(ImageFormat format, uint32_t width, uint32_t height, const void* data, TextureProperties properties); * * @brief Creates a new Texture2D * * @author <NAME> * @date 12/09/2021 * * @param format Describes the format to use. * @param width The width. * @param height The height. * @param data The data. * @param properties The properties. * * @returns A Texture2D */ static Ref<Texture2D> Create(ImageFormat format, uint32_t width, uint32_t height, const void* data, TextureProperties properties); /** * @fn static Ref<Texture2D> LoadImageToMemory(const std::string& filePath, const bool& flipOnLoad = false, const bool& isCubemap = false); * * @brief Loads a image to memory * @warning Image must be cleared by the user with tnah::Texture2D::Free() * * @author <NAME> * @date 12/09/2021 * * @param filePath absolute or relative file path to image. * @param flipOnLoad (Optional) Flips the image on load (STB ONLY) * @param isCubemap (Optional) Tells the loader the provided image is a cubemap (KTX ONLY} * * @returns The image to memory. */ static Ref<Texture2D> LoadImageToMemory(const std::string& filePath, const bool& flipOnLoad = false, const bool& isCubemap = false); /** * @fn static Ref<Texture2D> Create(uint32_t width, uint32_t height); * * @brief Creates a new Texture2D * * @author <NAME> * @date 12/09/2021 * * @param width The width. * @param height The height. * * @returns A Texture2D */ static Ref<Texture2D> Create(uint32_t width, uint32_t height); /** * @fn static Ref<Texture2D> Create(const std::string& path, const std::string& textureName = "", bool loadFromMemory = false, void* assimpTexture = nullptr); * * @brief Creates a new Texture2D * * @author <NAME> * @date 12/09/2021 * * @param path Full pathname of the file. * @param textureName (Optional) Name of the texture. * @param loadFromMemory (Optional) True to load from memory. * @param [in,out] assimpTexture (Optional) If non-null, the assimp texture. * * @returns A Texture2D */ static Ref<Texture2D> Create(const std::string& path, const std::string& textureName = "", bool loadFromMemory = false, void* assimpTexture = nullptr); /** * @fn virtual void Free() = 0; * * @brief Frees this object * * @author <NAME> * @date 12/09/2021 */ virtual void Free() = 0; /** * @fn virtual void Free(void* data) = 0; * * @brief Frees the given data * * @author <NAME> * @date 12/09/2021 * * @param [in,out] data If non-null, the data. */ virtual void Free(void* data) = 0; /** * @fn virtual uint32_t GetRendererID() const * * @brief Gets renderer identifier * * @author <NAME> * @date 12/09/2021 * * @returns The renderer identifier. */ virtual uint32_t GetRendererID() const { return m_RendererID; } /** * @fn virtual uint32_t GetTextureSlot() const * * @brief Gets texture slot * * @author <NAME> * @date 12/09/2021 * * @returns The texture slot. */ virtual uint32_t GetTextureSlot() const { return m_Slot; } /** * @fn virtual void SetData(void* data, uint32_t size) = 0; * * @brief Sets data * * @author <NAME> * @date 12/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ virtual void SetData(void* data, uint32_t size) = 0; /** * @fn virtual void Bind(uint32_t slot) const = 0; * * @brief Binds the given slot * * @author <NAME> * @date 12/09/2021 * * @param slot The slot. */ virtual void Bind(uint32_t slot) const = 0; /** * @fn virtual void Bind() const = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() const = 0; /** @brief Identifier for the renderer */ uint32_t m_RendererID = 0; /** @brief The slot */ uint32_t m_Slot = 0; private: /** * @fn static Ref<Texture2D> LoadKTXImage(const std::string& filePath, const bool& isKtx2 = false); * * @brief Loads ktx image * * @author <NAME> * @date 12/09/2021 * * @param filePath Full pathname of the file. * @param isKtx2 (Optional) True if is ktx 2, false if not. * * @returns The ktx image. */ static Ref<Texture2D> LoadKTXImage(const std::string& filePath, const bool& isKtx2 = false); /** * @fn static std::string KtxErrorReason(const int& ktxError); * * @brief Ktx error reason * * @author <NAME> * @date 12/09/2021 * * @param ktxError The ktx error. * * @returns A std::string. */ static std::string KtxErrorReason(const int& ktxError); /** * @fn static Ref<Texture2D> LoadSTBiImage(const std::string& filePath, const bool& flipOnLoad = false); * * @brief Loads stbi image * * @author <NAME> * @date 12/09/2021 * * @param filePath Full pathname of the file. * @param flipOnLoad (Optional) True to flip on load. * * @returns The st bi image. */ static Ref<Texture2D> LoadSTBiImage(const std::string& filePath, const bool& flipOnLoad = false); /** * @fn static CubemapInformation FindCubemapInfo(Ref<Texture2D> texture); * * @brief Searches for the first cubemap information * * @author <NAME> * @date 12/09/2021 * * @param texture The texture. * * @returns The found cubemap information. */ static CubemapInformation FindCubemapInfo(Ref<Texture2D> texture); }; /** * @class Texture3D * * @brief A texture 3d class that inherits from the Texture class. Used for 3D Textures like a Skybox * * @author <NAME> * @date 12/09/2021 */ class Texture3D : public Texture { public: /** * @fn static Ref<Texture3D> Texture3D::Create(const std::vector<std::string>& paths, const std::string& textureName = ""); * * @brief Creates a new Texture3D * * @author <NAME> * @date 12/09/2021 * * @param paths The paths. * @param textureName (Optional) Name of the texture. * * @returns A Texture3D */ static Ref<Texture3D> Create(const std::vector<std::string>& paths, const std::string& textureName = ""); /** * @fn static Ref<Texture3D> Texture3D::Create(const Texture3DProperties& properties, const std::string& textureName = "Cubemap"); * * @brief Creates a new Texture3D * * @author <NAME> * @date 12/09/2021 * * @param properties The properties. * @param textureName (Optional) Name of the texture. * * @returns A Texture3D */ static Ref<Texture3D> Create(const Texture3DProperties& properties, const std::string& textureName = "Cubemap"); /** * @fn virtual uint32_t Texture3D::GetRendererID() const * * @brief Gets renderer identifier * * @author <NAME> * @date 12/09/2021 * * @returns The renderer identifier. */ virtual uint32_t GetRendererID() const { return m_RendererID; } /** * @fn virtual uint32_t Texture3D::GetTextureSlot() const * * @brief Gets texture slot * * @author <NAME> * @date 12/09/2021 * * @returns The texture slot. */ virtual uint32_t GetTextureSlot() const { return m_Slot; } /** * @fn virtual void Texture3D::SetData(void* data, uint32_t size) = 0; * * @brief Sets data * * @author <NAME> * @date 12/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ virtual void SetData(void* data, uint32_t size) = 0; /** * @fn virtual void Texture3D::Bind(uint32_t slot) const = 0; * * @brief Binds the given slot * * @author <NAME> * @date 12/09/2021 * * @param slot The slot. */ virtual void Bind(uint32_t slot) const = 0; /** * @fn virtual void Texture3D::Bind() const = 0; * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ virtual void Bind() const = 0; /** @brief Identifier for the renderer */ uint32_t m_RendererID = 0; /** @brief The slot */ uint32_t m_Slot = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Timer.h
<reponame>BryceStandley/TNAH #pragma once #include <chrono> namespace tnah { /** * @class Timer * * @brief A timer class used to manage aspects of time * * @author <NAME> * @date 7/09/2021 */ class Timer { public: /** * @fn Timer::Timer() * * @brief Default constructor * * @author <NAME> * @date 7/09/2021 */ Timer() { Reset(); } /** * @fn inline void Timer::Reset() * * @brief Resets this object * * @author <NAME> * @date 7/09/2021 */ inline void Reset() { m_Start = std::chrono::high_resolution_clock::now(); } /** * @fn inline float Timer::Elapsed() * * @brief Gets the elapsed time * * @author <NAME> * @date 7/09/2021 * * @returns A float. */ inline float Elapsed() { return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - m_Start).count() * 0.001f * 0.001f * 0.001f; } /** * @fn inline float Timer::ElapsedMillis() * * @brief Returns Elapsed milliseconds * * @author <NAME> * @date 7/09/2021 * * @returns A float. */ inline float ElapsedMillis() { return Elapsed() * 1000.0f; } private: /** @brief The start */ std::chrono::time_point<std::chrono::high_resolution_clock> m_Start; }; }
BryceStandley/TNAH
core/src/Platform/OpenGL/OpenGLShader.h
<filename>core/src/Platform/OpenGL/OpenGLShader.h #pragma once #include "TNAH/Renderer/Shader.h" #include <glm/glm.hpp> // TODO: REMOVE! typedef unsigned int GLenum; namespace tnah { class OpenGLShader : public Shader { public: /** * @fn OpenGLShader::OpenGLShader(const std::string& shaderFilePath); * * @brief A constructor that takes in a path to the shader and generates it * * @author <NAME> * @date 7/09/2021 * * @param shaderFilePath - represents the path to the vertex shader. * * case) */ OpenGLShader(const std::string& shaderFilePath); /** * @fn OpenGLShader::OpenGLShader(const std::string& vertexSrc, const std::string& fragmentSrc); * * @brief Constructor that takes in the paths for both the fragment and vertex shaders * * @author <NAME> * @date 7/09/2021 * * @param vertexSrc The vertex source. * @param fragmentSrc The fragment source. */ OpenGLShader(const std::string& vertexSrc, const std::string& fragmentSrc); /** * @fn OpenGLShader::~OpenGLShader(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ ~OpenGLShader(); /** * @fn void OpenGLShader::Bind() override; * * @brief Allows you to activate and use the shader * * @author <NAME> * @date 7/09/2021 */ void Bind() override; /** * @fn void OpenGLShader::Unbind() override; * * @brief Unbind the shader from the program. * * @author <NAME> * @date 7/09/2021 */ void Unbind() override; /** * @fn bool OpenGLShader::IsBound() const override * * @brief Queries if this object is bound * * @author <NAME> * @date 7/09/2021 * * @returns True if bound, false if not. */ bool IsBound() const override { return m_Bound; } /** * @fn virtual void OpenGLShader::SetBool(const std::string& name, bool value) override; * * @brief Sets a boolean for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetBool(const std::string& name, bool value) override; /** * @fn virtual void OpenGLShader::SetInt(const std::string& name, int value) override; * * @brief Sets an integer for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetInt(const std::string& name, int value) override; /** * @fn virtual void OpenGLShader::SetFloat(const std::string& name, float value) override; * * @brief Sets a float for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetFloat(const std::string& name, float value) override; /** * @fn virtual void OpenGLShader::SetVec2(const std::string& name, const glm::vec2& value) override; * * @brief Sets a vec2 for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetVec2(const std::string& name, const glm::vec2& value) override; /** * @fn virtual void OpenGLShader::SetVec3(const std::string& name, const glm::vec3& value) override; * * @brief Sets a vec3 for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetVec3(const std::string& name, const glm::vec3& value) override; /** * @fn virtual void OpenGLShader::SetVec4(const std::string& name, const glm::vec4& value) override; * * @brief Sets a vec4 for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param value - represents the variable value. */ virtual void SetVec4(const std::string& name, const glm::vec4& value) override; /** * @fn virtual void OpenGLShader::SetMat3(const std::string& name, const glm::mat3& mat) override; * * @brief Sets a mat3 for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param mat - represents the variable value. */ virtual void SetMat3(const std::string& name, const glm::mat3& mat) override; /** * @fn virtual void OpenGLShader::SetMat4(const std::string& name, const glm::mat4& mat) override; * * @brief Sets a mat4 for use in the shader program * * @author <NAME> * @date 7/09/2021 * * @param name - represents the name of the variable. * @param mat - represents the variable value. */ virtual void SetMat4(const std::string& name, const glm::mat4& mat) override; /** * @fn inline virtual const std::string& OpenGLShader::GetName() const override * * @brief Gets the name of the shader * * @author <NAME> * @date 7/09/2021 * * @returns The name of the shader. */ inline virtual const std::string& GetName() const override { return m_ShaderName; } private: /** * * @brief Allows for the processing of vertex and fragment shaders within a singular file * * @author <NAME> * @date 7/09/2021 * * @param source Source code of the shader. * @param shaderFilePath Full pathname of the shader file. * * @returns std::unordered_map<GLenum, std::pair<std::string, std::string>> * */ static std::unordered_map<GLenum, std::pair<std::string, std::string>> PreProcess(const std::string& source, const std::string& shaderFilePath); /** * @fn void OpenGLShader::Compile(const std::unordered_map<GLenum, std::pair<std::string, std::string>>& shaderSources); * * @brief Compiles the given shader sources * * @author <NAME> * @date 7/09/2021 * * @param shaderSources The shader sources. */ void Compile(const std::unordered_map<GLenum, std::pair<std::string, std::string>>& shaderSources); /** * @fn std::string OpenGLShader::ReadFile(const std::string& filepath); * * @brief Reads a file from a given filepath * * @author <NAME> * @date 7/09/2021 * * @param filepath The filepath. * * @returns The file. */ std::string ReadFile(const std::string& filepath); /** * @fn std::string OpenGLShader::PreProcessPaths(const std::string& shaderSorceFilePath); * * @brief Applies pre-processing to the paths * * @author <NAME> * @date 7/09/2021 * * @param shaderSorceFilePath Full pathname of the shader source file. * * @returns A std::string. */ std::string PreProcessPaths(const std::string& shaderSorceFilePath); /** @brief Identifier for the shader */ uint32_t m_ShaderID; /** @brief True to bound */ bool m_Bound = false; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/Character.h
#pragma once #include "Actions.h" #include "EmotionComponent.h" #include "StateMachine.h" namespace tnah { /** * @class Character * * @brief * * @author <NAME> * @date 2/11/2021 */ class Character : public RefCounted { public: /** * @fn OnUpdate * * @brief Updates the character according to deltaTime * * @author <NAME> * @date 2/11/2021 * * @param deltaTime - the timestep of the update * @param transform - the transform component of the character * @return glm::vec3 - the target position of the character */ virtual glm::vec3 OnUpdate(Timestep deltaTime,TransformComponent &transform) = 0; /** * @fn ~Character * * @brief Virtual Destructor * * @author <NAME> * @date 2/11/2021 * */ virtual ~Character() = default; /** * @fn GetDeltaTime * * @brief Gets the deltatime * * @author <NAME> * @date 2/11/2021 * * @return float - the deltaTime */ float GetDeltaTime() const {return mDt;} /** * @fn SetDeltaTime * * @brief sets the deltatime using the provided parameter * * @author <NAME> * @date 2/11/2021 * * @param t - the deltatime value to be set */ void SetDeltaTime(const float t) {mDt = t;} /** * @fn SetDesiredAction * * @brief Sets the desired action that the NPC would like to perform, using the provided Action parameter * * @author <NAME> * @date 2/11/2021 * * @param a - an enum Action value */ void SetDesiredAction(const Actions a) {mDesiredAction = a;} /** * @fn GetDesiredAction * * @brief Gets the desired action of the NPC * * @author <NAME> * @date 2/11/2021 * * @return Action - the desired action */ Actions GetDesiredAction() const {return mDesiredAction;} /** * @fn SetDistance * * @brief Sets the affordance distance of the NPC * * @author <NAME> * @date 2/11/2021 * * @param d - the affordance distance */ void SetDistance(const float d) {affordanceDistance = d;} /** * @fn GetDistance * * @brief Gets the affordance distance * * @author <NAME> * @date 2/11/2021 * * @return float - the affordance distance */ float GetDistance() const {return affordanceDistance;} /** * @fn CheckAction * * @brief Checks the action * * @author <NAME> * @date 2/11/2021 * * @param affordanceValue * @param distance * @param tag * @return */ virtual std::pair<bool, bool> CheckAction(float affordanceValue, float distance, std::string tag) = 0; /** * @fn LogAction * * @brief Logs the action of the character, which can be displayed via text on the screen. * * @author <NAME> * @date 2/11/2021 * * @param text - the output of the character * @param colour - the colour of the text */ void LogAction(std::string text, glm::vec4 colour); ///CHARACTER NAME std::string name; /** * @fn GetWander * * @brief Gets the bool that determines whether or not the character is wandering * * @author <NAME> * @date 2/11/2021 * * @return bool - the wander flag */ bool GetWander() {return wander;} /** * @fn SetWander * * @brief Grants the ability to set the characters wander flag to true or false using the boolean parameter * * @author <NAME> * @date 2/11/2021 * * @param w */ void SetWander(bool w) {wander = w;} /** * @fn SetSpeed * * @brief Sets the movement speed of the character * * @author <NAME> * @date 2/11/2021 * * @param s - the speed value that will be assigned to speed */ void SetSpeed(float s) {speed = s;} /** * @fn GetSpeed * * @brief Gets the movement speed of the character * * @author <NAME> * @date 2/11/2021 * * @return float - the character speed */ float GetSpeed() {return speed;} /** * @fn ApplyPlayerAction * * @brief Can be used to apply actions of the player to the NPC * * @author <NAME> * @date 2/11/2021 * * @param givenAction - refers to the given player action, which will be applied to the NPC character */ virtual void ApplyPlayerAction(PlayerActions givenAction) = 0; /** * @fn CharacterString * * @brief Gets the character information string that include Emotion and Action Information * * @author <NAME> * @date 2/11/2021 * * @return string - the Character information string */ virtual std::string CharacterString() = 0; /** * @fn GetActionString * * @brief Gets the string containing action information * * @author <NAME> * @date 2/11/2021 * * @param action - refers to the action that we will convert to string * @return string - the action information string */ static std::string GetActionString(Actions action); protected: /** * @fn BalanceRange * * @brief Used to balance the given value between the given min and max values * * @author Chris Logan * @date 2/11/2021 * * @param min - the minimum value * @param max - the maximum value * @param balanceValue - the value that is balanced * @return float */ static float BalanceRange(float min, float max, float balanceValue) { if (balanceValue < min) return min; if (balanceValue > max) return max; return 0; } private: /// deltaTime float mDt = 0.0f; /// the desired action Actions mDesiredAction = Actions::sit; /// the affordance distance of the npc float affordanceDistance = 0.0f; /// true to wander, false to not bool wander = false; /// movement speed float speed = 1.0f; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Serializer.h
#pragma once #include "Scene.h" #include "Components/AI/Affordance.h" #include "Components/AI/AIComponent.h" #include "Components/AI/CharacterComponent.h" #include "TNAH/Physics/Collider.h" namespace tnah { class Serializer { public: /** * @brief Public serializer save scene function * @author <NAME> * @date 06-11-2021 * @return true * @return false */ static bool SaveScene(Ref<Scene> scene, const std::string& saveFilePath); /** * @brief Public serializer load scene function * @author <NAME> * @date 06-11-2021 * @return Ref<Scene> */ static Ref<Scene> LoadScene(const std::string& saveFilePath); private: /** * * \fn Ref<Scene> DeserializeScene * * \brief Deserializes a scene from a file into memory * * \author <NAME> * \date 13/9/2021 * * \param filePath * * \return * */ static Ref<Scene> DeserializeScene(const std::string& filePath); /** * * \fn bool SerializeScene * * \brief Serializes the scene to the given file path * * \author <NAME> * \date 13/9/2021 * * \param scene * \param filePath * * \return * */ static bool SerializeScene(Ref<Scene> scene, const std::string& filePath); /** * * \fn std::string GenerateGlobalSettings * * \brief Generates global settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param scene * * \return * */ static std::string GenerateGlobalSettings(Ref<Scene> scene); /** * * \fn std::string GenerateSceneSettings * * \brief Generates scene settings to serialize * * \author Bryce Standley * \date 13/9/2021 * * \param scene * * \return * */ static std::string GenerateSceneSettings(Ref<Scene> scene); //Components /** * * \fn std::string GenerateTransform * * \brief Generates transform settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param transform * \param totalTabs * * \return * */ static std::string GenerateTransform(const TransformComponent& transform, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateCamera * * \brief Generates Camera settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param camera * \param totalTabs * * \return * */ static std::string GenerateCamera(const SceneCamera& camera, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateSkybox * * \brief Generates skybox settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param skybox * \param totalTabs * * \return * */ static std::string GenerateSkybox(const SkyboxComponent& skybox, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateTerrain * * \brief Generates transform terrain to serialize * * \author <NAME> * \date 13/9/2021 * * \param terrain * \param totalTabs * * \return * */ static std::string GenerateTerrain(const TerrainComponent& terrain, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateMesh * * \brief Generates mesh settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param mesh * \param totalTabs * * \return * */ static std::string GenerateMesh(const MeshComponent& mesh, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateLight * * \brief Generates light settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param light * \param totalTabs * * \return * */ static std::string GenerateLight(const LightComponent& light, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateAudioListener * * \brief Generates audio listener settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param sound * \param totalTabs * * \return * */ static std::string GenerateAudioListener(const AudioListenerComponent& sound, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateAudioSource * * \brief Generates audio source settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param sound * \param totalTabs * * \return * */ static std::string GenerateAudioSource(const AudioSourceComponent& sound, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateRigidBody * * \brief Generates rigidbody settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param rb * \param totalTabs * * \return * */ static std::string GenerateRigidBody(const RigidBodyComponent& rb, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateCollider(const Ref<Physics::Collider>& col, const uint32_t& totalTabs = 0); * * \brief Generates collider settings to serialize * * \author <NAME> * \date 13/9/2021 * * \param col * \param totalTabs * * \return string * */ static std::string GenerateCollider(const Ref<Physics::Collider>& col, const uint32_t& totalTabs = 0); /** * @brief Generates a AI conponent to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateAi(const AIComponent& ai, const CharacterComponent &c,const uint32_t& totalTabs = 0); /** * @brief Generates a Astar component to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateAStar(const AStarComponent& astar, const uint32_t& totalTabs = 0); /** * @brief Generates a Astar obstacle component to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateAStarObstacle(const AStarObstacleComponent& astar, const uint32_t& totalTabs = 0); /** * @brief Generates a Affordance component to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateAffordance(Affordance& astar, const uint32_t& totalTabs = 0); //Tag creators /** * * \fn std::string GenerateTagOpen(const std::string& tagType, const uint32_t& totalTabs = 0); * * \brief Generates open tags with a custom type * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param totalTabs * * \return * */ static std::string GenerateTagOpen(const std::string& tagType, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateTagClose(const std::string& tagType, const uint32_t& totalTabs = 0); * * \brief Generates close tags with a custom type * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param totalTabs * * \return * */ static std::string GenerateTagClose(const std::string& tagType, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateTagOpen(const char* tagType, const uint32_t& totalTabs = 0); * * \brief Generates open tags with a custom type * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param totalTabs * * \return * */ static std::string GenerateTagOpen(const char* tagType, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateTagClose(const char* tagType, const uint32_t& totalTabs = 0); * * \brief Generates close tags with a custom type * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param totalTabs * * \return * */ static std::string GenerateTagClose(const char* tagType, const uint32_t& totalTabs = 0); //Helpers for different data types /** * * \fn std::string GenerateVec3(const glm::vec3& value, const uint32_t& totalTabs = 0); * * \brief Generates vec3 output for serialization * * \author <NAME> * \date 13/9/2021 * * \param value * \param totalTabs * * \return * */ static std::string GenerateVec3(const glm::vec3& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateVec4(const glm::vec4& value, const uint32_t& totalTabs = 0); * * \brief Generates vec4 output for serialization * * \author <NAME> * \date 13/9/2021 * * \param value * \param totalTabs * * \return * */ static std::string GenerateVec4(const glm::vec4& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const glm::vec3& value, const uint32_t& totalTabs = 0); * * \brief Generates vec3 entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const glm::vec3& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const glm::vec4& value, const uint32_t& totalTabs = 0); * * \brief Generates vec4 entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const glm::vec4& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateDirectoryEntry(const std::string& tagType, const std::string& path, const uint32_t& totalTabs = 0); * * \brief Generates directory entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param path * \param totalTabs * * \return * */ static std::string GenerateDirectoryEntry(const std::string& tagType, const std::string& path, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const float& value, const uint32_t& totalTabs = 0); * * \brief Generates value entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const float& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const int& value, const uint32_t& totalTabs = 0); * * \brief Generates value entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const int& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const bool& value, const uint32_t& totalTabs = 0); * * \brief Generates value entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const bool& value, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateTagEntry(const TagComponent& tag, const uint32_t& totalTabs = 0); * * \brief Generates value entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tag * \param totalTabs * * \return * */ static std::string GenerateTagEntry(const TagComponent& tag, const uint32_t& totalTabs = 0); /** * * \fn std::string GenerateValueEntry(const std::string& tagType, const std::string& value, const uint32_t& totalTabs = 0); * * \brief Generates value entry with custom type output for serialization * * \author <NAME> * \date 13/9/2021 * * \param tagType * \param value * \param totalTabs * * \return * */ static std::string GenerateValueEntry(const std::string& tagType, const std::string& value, const uint32_t& totalTabs = 0); /** * @brief Generates a Mat3 value entry to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateValueEntry(const std::string& tagType, const glm::mat3& value, const uint32_t& totalTabs = 0); /** * @brief Generates a quaternion value entry to serialize * @author <NAME> * @date 06-11-2021 * @return std::string */ static std::string GenerateValueEntry(const std::string& tagType, const glm::quat& value, const uint32_t& totalTabs = 0); private: /** * * \fn Ref<Scene> GetGlobalSettingsFromFile(Ref<Scene> scene, const std::string& fileContents, int& currentPos); * * \brief Gets global settings from a serialized file * * \author <NAME>andley * \date 13/9/2021 * * \param scene * \param fileContents * \param currentPos * * \return * */ static Ref<Scene> GetGlobalSettingsFromFile(Ref<Scene> scene, const std::string& fileContents, int& currentPos); /** * * \fn std::pair<size_t, size_t> FindTags(const std::string& tagToFind, const std::string& fileContents, size_t from = 0, size_t to = 0); * * \brief Finds tags within the open file * * \author <NAME> * \date 13/9/2021 * * \param tagToFind * \param fileContents * \param from * \param to * * \return * */ static std::pair<size_t, size_t> FindTags(const std::string& tagToFind, const std::string& fileContents, size_t from = 0, size_t to = 0); /** * * \fn bool CheckTags(std::pair<size_t, size_t> tags); * * \brief Checks if the given tags are valid * * \author <NAME> * \date 13/9/2021 * * \param tags * * \return * */ static bool CheckTags(std::pair<size_t, size_t> tags); /** * * \fn Ref<Scene> GetSceneStructureFromFile(Ref<Scene> scene, const std::string& fileContents, int& currentPos); * * \brief Gets the scene structure form the file contents * * \author <NAME> * \date 13/9/2021 * * \param scene * \param fileContents * \param currentPos * * \return * */ static Ref<Scene> GetSceneStructureFromFile(Ref<Scene> scene, const std::string& fileContents, int& currentPos); /** * * \fn Ref<Scene> GetGameObjectFromFile(Ref<Scene> scene, const std::string& fileContents, std::pair<size_t, size_t> gameObjectTagPositions); * * \brief Gets a game object from the file contents * * \author <NAME> * \date 13/9/2021 * * \param scene * \param fileContents * \param gameObjectTagPositions * * \return * */ static Ref<Scene> GetGameObjectFromFile(Ref<Scene> scene, const std::string& fileContents, std::pair<size_t, size_t> gameObjectTagPositions); /** * * \fn int FindAndAddComponentsFromFile(GameObject& gameObject, const std::string& fileContents, std::pair<size_t, size_t> gameObjectTagPositions); * * \brief Finds and adds a component to a game object from the file contents * * \author <NAME> * \date 13/9/2021 * * \param gameObject * \param fileContents * \param gameObjectTagPositions * * \return * */ static int FindAndAddComponentsFromFile(GameObject& gameObject, const std::string& fileContents, std::pair<size_t, size_t> gameObjectTagPositions); /** * * \fn TagComponent GetTagFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Gets a custom tag from the file contents * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static TagComponent GetTagFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn TransformComponent GetTransformFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<transform> </transform>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static TransformComponent GetTransformFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn SceneCamera GetCameraFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<camera> </camera>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static SceneCamera GetCameraFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn SkyboxComponent GetSkyboxFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<skybox> </skybox>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static SkyboxComponent GetSkyboxFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn TerrainComponent GetTerrainFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<terrain> </terrain>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static TerrainComponent GetTerrainFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn MeshComponent GetMeshFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<mesh> </mesh>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static MeshComponent GetMeshFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn void GetRigidBodyFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions, GameObject& gameObject); * * \brief Finds the all data for the scene within '<rigidbody> </rigidbody>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * \param gameObject * * \return * */ static void GetRigidBodyFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions, GameObject& gameObject); /** * * \fn bool GetColliderFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions, RigidBodyComponent& rb); * * \brief Finds the all data for the scene within '<boxCollider> </boxCollider>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * \param rb * * \return * */ static bool GetColliderFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions, RigidBodyComponent& rb); /** * * \fn PlayerControllerComponent GetPlayerControllerFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<playerControl> </playerControl>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static PlayerControllerComponent GetPlayerControllerFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn NativeScriptComponent GetNativeScriptFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<native> </native>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static NativeScriptComponent GetNativeScriptFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn LightComponent GetLightFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds the all data for the scene within '<light> </light>' tags * * \author <NAME> * \date 13/9/2021 * * \param fileContents * \param componentTagPositions * * \return * */ static LightComponent GetLightFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * @brief Get the Ai From File * @author <NAME> * @date 06-11-2021 * @return CharacterNames */ static CharacterNames GetAiFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * @brief Get the Astar From File * @author <NAME> * @date 06-11-2021 * @return AStarComponent */ static AStarComponent GetAstarFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * @brief Get the Astar Obstacle From File * @author <NAME> * @date 06-11-2021 * @return true * @return false */ static bool GetAstarObstacleFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * @brief Get the Affordances From File * @author <NAME> * @date 06-11-2021 * @return Affordance */ static Affordance GetAffordancesFromFile(const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn glm::vec3 GetVec3FromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds values of a vec3 for a component with a given search tag * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static glm::vec3 GetVec3FromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn glm::vec4 GetVec4FromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds values of a vec4 for a component with a given search tag * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static glm::vec4 GetVec4FromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn std::string GetDirectoryFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds a path from a directory entry between <directory> </directory> tags * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static std::string GetDirectoryFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn int GetIntValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds a int value between <value> </value> tags * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static int GetIntValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn float GetFloatValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds a float value between <value> </value> tags * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static float GetFloatValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn bool GetBoolValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds a bool value between <value> </value> tags * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static bool GetBoolValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn std::string GetStringValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); * * \brief Finds a string value between <value> </value> tags * * \author <NAME> * \date 13/9/2021 * * \param tagName * \param fileContents * \param componentTagPositions * * \return * */ static std::string GetStringValueFromFile(const std::string& tagName, const std::string& fileContents, std::pair<size_t, size_t> componentTagPositions); /** * * \fn void GenerateValuesLoadError(const std::string& tagName); * * \brief Generates a error if a vaule failed to load * * \author <NAME> * \date 13/9/2021 * * \param tagName * * */ static void GenerateValuesLoadError(const std::string& tagName); /** @brief Resource of the current scene */ static Resource s_SceneResource; friend class EditorLayer; friend class Editor; }; }
BryceStandley/TNAH
core/src/TNAH/Core/EntryPoint.h
#pragma once #include "TNAH/Core/Core.h" #ifdef TNAH_PLATFORM_WINDOWS /** * @fn extern tnah::Application* tnah::CreateApplication(); * * @brief Creates the application * * @author <NAME> * @date 7/09/2021 * * @returns Null if it fails, else the new application. */ extern tnah::Application* tnah::CreateApplication(); /** * @fn int main(int argc, char** argv) * * @brief Main entry-point for this application * * @author <NAME> * @date 7/09/2021 * * @param argc The number of command-line arguments provided. * @param argv An array of command-line argument strings. * * @returns Exit-code for the process - 0 for success, else an error code. */ int main(int argc, char** argv) { tnah::Log::Init(); auto app = tnah::CreateApplication(); app->Run(); delete app; } #endif
BryceStandley/TNAH
core/src/TNAH/Debug/Debug.h
#pragma once /** * @namespace tnah::Debug {} * * @brief Debug Sub-namespace */ namespace tnah::Debug{ /** * @brief Debugs info as core info of a vec3 with a message * @author <NAME> * @date 07-11-2021 */ static void CoreInfo(const glm::vec3& value, const std::string& message = "") { TNAH_CORE_INFO("(Debug): {0}: X({1}) - Y({2}) - Z({3})",message, value.x, value.y, value.z); } /** * @brief Debugs info as core info of a quaternion with a message * @author <NAME> * @date 07-11-2021 */ static void CoreInfo(const glm::quat& val, const std::string& message = "") { TNAH_CORE_INFO("(Debug): {0}: X({1}) - Y({2}) - Z({3}) - W({4})",message, val.x, val.y, val.z, val.w); } /** * @brief Debugs info as core info of a vec3 * @author <NAME> * @date 07-11-2021 */ static void CoreInfo(const glm::vec3& value) { TNAH_CORE_INFO("(Debug): X({0}) - Y({1}) - Z({2})", value.x, value.y, value.z); } /** * @brief Debugs warning as core info of a vec3 * @author <NAME> * @date 07-11-2021 */ static void CoreWarm(const glm::vec3& value) { TNAH_CORE_WARN("(Debug): X({0}) - Y({1}) - Z({2})", value.x, value.y, value.z); } /** * @brief Debugs error as core info of a vec3 * @author <NAME>andley * @date 07-11-2021 */ static void CoreError(const glm::vec3& value) { TNAH_CORE_ERROR("(Debug): X({0}) - Y({1}) - Z({2})", value.x, value.y, value.z); } }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AI/StateMachine.h
<gh_stars>1-10 #pragma once namespace tnah { /** * @class state * @brief An abstract class that provides a common interface to all state classes. It is templated so that class can be reused in any state machine. * * @author <NAME> * @version 01 * @date 25/04/2021 <NAME>, Started * * **/ template<class entity> class State { public: /** * @brief virtual destructor * */ virtual ~State() {} /** * @brief pure virtual function that represents the enter point of the state * @param entity* - a pointer to the entity class */ virtual void Enter(entity*) = 0; /** * @brief pure virtual function that represents the execute stage of the state * @param entity* - a pointer to the entity class */ virtual void Execute(entity*) = 0; /** * @brief pure virtual function that represents the exit stage of the state * @param entity* - a pointer to the entity class */ virtual void Exit(entity*) = 0; }; /** * @class stateMachine * @brief An templated stateMachine class that encapsulates all state related data and functions, allowing for a cleaner integration of an FSM thst can be used in the entity's class * * @author <NAME> * @version 01 * @date 27/04/2021 <NAME>, Started * * **/ template<class entity> class StateMachine { private: /// pointer to the owner of the FSM entity* owner; /// pointer to the previous state of the FSM State<entity>* previousState; /// pointer to the current state of the FSM State<entity>* currentState; /// pointer to the global state of the FSM State<entity>* globalState; public: /* * @brief Constructor that assigns the state machine to an owner and initialises all states to nullptr * @param FSMowner - a pointer to the owner of the finite state machine */ StateMachine(entity* FSMowner) { owner = FSMowner; previousState = nullptr; currentState = nullptr; globalState = nullptr; } /* * @brief sets the previous state of the FSM to the state provided * @param st - a pointer to the state you want to set as the previous state */ void setPreviousState(State<entity>* st) { previousState = st; } /* * @brief sets the current state of the FSM to the state provided * @param st - a pointer to the state you want to set as the current state */ void setCurrentState(State<entity>* st) { currentState = st; } /* * @brief sets the global state of the FSM to the state provided * @param st - a pointer to the state you want to set as the global state */ void setGlobalState(State<entity>* st) { globalState = st; } /* * @brief updates and executes the FSM depending on which state its in * */ void update() const { if (globalState) globalState->Execute(owner); if (currentState) currentState->Execute(owner); } /* * @brief allows for the FSM to easily change states * @param newState - a pointer to the state the FSM will change to */ void changeState(State<entity>*newState) { if(currentState != nullptr) { previousState = currentState; ///exit state currentState->Exit(owner); ///change current state to new state } currentState = newState; ///enter the new current state currentState->Enter(owner); } /* * @brief reverts the current state back to the previous one * */ void revertToPreviousState() { currentState = previousState; } /* * @brief gets and returns the previousState of the state machine * @return State<entity>* */ State<entity>* getPreviousState() { return previousState; } /* * @brief gets and returns the currentState of the state machine * @return State<entity>* */ State<entity>* getCurrentState() { return currentState; } /* * @brief gets and returns the globalState of the state machine * @return State<entity>* */ State<entity>* getGlobalState() { return globalState; } /* * @brief checks if the current state is in the same state to the one passed as parameter. Returns true if so. * @return bool */ bool isInState(const State<entity>&st) const { return typeid(*currentState) == typeid(st); } /* * @brief virtual destructor */ ~StateMachine() { } }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Light.h
#pragma once #include <TNAH/Core/Core.h> #include <glm/glm.hpp> #include "Shader.h" namespace tnah { /** * @class Light * * @brief A light class that inherits from the refCounted class to allow the use of ref pointers. Responsible for lighting in applications * * @author <NAME> * @date 12/09/2021 */ class Light : public RefCounted { public: /** * @enum LightType * * @brief Values that represent light types */ enum class LightType { Directional = 0, Point = 1, Spot = 2 }; /** * @struct ShaderLightInformation * * @brief Information about the shader light. * * @author <NAME> * @date 12/09/2021 */ struct ShaderLightInformation { /** * @brief Shader light type, 0 = Directional, 1 = Point, 2 = Spot, Any other value = disabled * lightng in shader. */ int type = 0; /** @brief Camera View */ glm::vec3 cameraPosition = glm::vec3(0.0f); /** @brief The light position */ glm::vec3 position = glm::vec3(0.0f); /** @brief The light direction direction */ glm::vec3 direction = glm::vec3(0.0f); /** @brief The ambient lighting */ glm::vec3 ambient = glm::vec3(0.0f); /** @brief The diffuse lighting */ glm::vec3 diffuse = glm::vec3(0.0f); /** @brief The specular lighting */ glm::vec3 specular = glm::vec3(0.0f); /** @brief The color of the light */ glm::vec3 color = glm::vec3(0.0f); /** @brief The intensity */ float intensity = 1.0f; /** @brief the constant */ float constant = 0.0f; /** @brief The linear */ float linear = 0.0f; /** @brief The quadratic */ float quadratic = 0.0f; /** @brief The cutoff for a spotlight */ float cutoff = 0.0f; }; /** * @fn Light::Light(LightType type) * * @brief Constructor * * @author <NAME> * @date 12/09/2021 * * @param type The type of light. */ Light(LightType type) :m_Type(type) {} /** * @fn virtual Light::~Light() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Light() = default; /** * @fn static Ref<Light> Light::Create(LightType type); * * @brief Creates a new light of the given type * * @author <NAME> * @date 12/09/2021 * * @param type The type of light. * * @returns A Ref&lt;Light&gt; */ static Ref<Light> Create(LightType type); /** * @fn static Ref<Light> Light::CreateDirectional(const glm::vec3& direction, const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular); * * @brief Creates a directional light * * @author <NAME> * @date 12/09/2021 * * @param direction The direction. * @param ambient The ambient. * @param diffuse The diffuse. * @param specular The specular. * * @returns The new directional light. */ static Ref<Light> CreateDirectional(const glm::vec3& direction, const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular); /** * @fn static Ref<Light> Light::CreateDirectional(); * * @brief Creates the directional light * * @author <NAME> * @date 12/09/2021 * * @returns The new directional light. */ static Ref<Light> CreateDirectional(); /** * @fn static Ref<Light> Light::CreatePoint(const float& constant, const float& linear, const float& quadratic); * * @brief Creates a point light * * @author <NAME> * @date 12/09/2021 * * @param constant The constant. * @param linear The linear. * @param quadratic The quadratic. * * @returns The new point light. */ static Ref<Light> CreatePoint(const float& constant, const float& linear, const float& quadratic); /** * @fn static Ref<Light> Light::CreatePoint(); * * @brief Creates a point light * * @author <NAME> * @date 12/09/2021 * * @returns The new point light. */ static Ref<Light> CreatePoint(); /** * @fn static Ref<Light> Light::CreateSpot(const float& cutoff); * * @brief Creates a spot light * * @author <NAME> * @date 12/09/2021 * * @param cutoff The cutoff. * * @returns The new spot light. */ static Ref<Light> CreateSpot(const float& cutoff); /** * @fn static Ref<Light> Light::CreateSpot(); * * @brief Creates a spot light * * @author <NAME> * @date 12/09/2021 * * @returns The new spot light. */ static Ref<Light> CreateSpot(); /** * @fn virtual void Light::SetColor(const glm::vec4& value) * * @brief Sets a color of the light * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetColor(const glm::vec4& value) { m_Color = value; } /** * @fn virtual void Light::SetIntensity(const float& value) * * @brief Sets light intensity * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetIntensity(const float& value) { m_Intensity = value; } /** * @fn virtual void Light::SetPosition(const glm::vec3& value) * * @brief Sets the light position * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetPosition(const glm::vec3& value) {m_Position = value; } /** * @fn virtual void Light::SetType(const LightType& type) * * @brief Sets the light type * * @author <NAME> * @date 12/09/2021 * * @param type The type. */ virtual void SetType(const LightType& type) { m_Type = type; } /** * @fn virtual glm::vec4& Light::GetColor() * * @brief Gets the color * * @author <NAME> * @date 12/09/2021 * * @returns The color. */ virtual glm::vec4& GetColor() { return m_Color; } /** * @fn virtual float& Light::GetIntensity() * * @brief Gets the intensity * * @author <NAME> * @date 12/09/2021 * * @returns The intensity. */ virtual float& GetIntensity() { return m_Intensity; } /** * @fn virtual LightType& Light::GetType() * * @brief Gets the type * * @author <NAME> * @date 12/09/2021 * * @returns The type. */ virtual LightType& GetType() { return m_Type; } /** * @fn virtual glm::vec3& Light::GetPosition() * * @brief Gets the position * * @author <NAME> * @date 12/09/2021 * * @returns The position. */ virtual glm::vec3& GetPosition() { return m_Position; } /** * @fn ShaderLightInformation& Light::GetShaderInfo() * * @brief Gets shader information * * @author <NAME> * @date 12/09/2021 * * @returns The shader information. */ ShaderLightInformation& GetShaderInfo() { return m_ShaderLightInformation; } /** * @fn virtual void Light::SetDirection(const glm::vec3& value) * * @brief Sets a direction * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetDirection(const glm::vec3& value) { m_Direction = value; } /** * @fn virtual void Light::SetDiffuse(const glm::vec3& value) * * @brief Sets a diffuse value * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetDiffuse(const glm::vec3& value) { m_Diffuse = value; } /** * @fn virtual void Light::SetAmbient(const glm::vec3& value) * * @brief Sets an ambient value * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetAmbient(const glm::vec3& value) { m_Ambient = value; } /** * @fn virtual void Light::SetSpecular(const glm::vec3& value) * * @brief Sets a specular value * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetSpecular(const glm::vec3& value) { m_Specular = value; } /** * @fn virtual glm::vec3& Light::GetDirection() * * @brief Gets the direction * * @author <NAME> * @date 12/09/2021 * * @returns The direction. */ virtual glm::vec3& GetDirection() { return m_Direction; } /** * @fn virtual glm::vec3& Light::GetAmbient() * * @brief Gets the ambient * * @author <NAME> * @date 12/09/2021 * * @returns The ambient. */ virtual glm::vec3& GetAmbient() { return m_Ambient; } /** * @fn virtual glm::vec3& Light::GetDiffuse() * * @brief Gets the diffuse * * @author <NAME> * @date 12/09/2021 * * @returns The diffuse. */ virtual glm::vec3& GetDiffuse() { return m_Diffuse; } /** * @fn virtual glm::vec3& Light::GetSpecular() * * @brief Gets the specular * * @author <NAME> * @date 12/09/2021 * * @returns The specular. */ virtual glm::vec3& GetSpecular() { return m_Specular;} /** * @fn virtual void Light::SetConstant(const float& value) * * @brief Sets a constant * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetConstant(const float& value) { m_Constant = value; } /** * @fn virtual void Light::SetLinear(const float& value) * * @brief Sets a linear * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetLinear(const float& value) { m_Linear = value; } /** * @fn virtual void Light::SetQuadratic(const float& value) * * @brief Sets a quadratic * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetQuadratic(const float& value) { m_Quadratic = value; } /** * @fn virtual void Light::SetCutOff(const float& value) * * @brief Sets cut off * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetCutOff(const float& value) { m_CutOff = glm::radians(value); } /** * @fn virtual void Light::SetDistance(const int& value) * * @brief Sets a distance * * @author <NAME> * @date 12/09/2021 * * @param value The value. */ virtual void SetDistance(const int& value) { m_Distance = value; } /** * @fn virtual float& Light::GetConstant() * * @brief Gets the constant * * @author <NAME> * @date 12/09/2021 * * @returns The constant. */ virtual float& GetConstant() { return m_Constant; } /** * @fn virtual float& Light::GetLinear() * * @brief Gets the linear * * @author <NAME> * @date 12/09/2021 * * @returns The linear. */ virtual float& GetLinear() { return m_Linear; } /** * @fn virtual float& Light::GetQuadratic() * * @brief Gets the quadratic * * @author <NAME> * @date 12/09/2021 * * @returns The quadratic. */ virtual float& GetQuadratic() { return m_Quadratic; } /** * @fn virtual float Light::GetCutOff() * * @brief Gets cut off * * @author <NAME> * @date 12/09/2021 * * @returns The cut off. */ virtual float GetCutOff() { return glm::degrees(m_CutOff); } /** * @fn virtual int& Light::GetDistance() * * @brief Gets the distance * * @author <NAME> * @date 12/09/2021 * * @returns The distance. */ virtual int& GetDistance() { return m_Distance; } /** * @fn virtual void Light::UpdateShaderLightInfo(const glm::vec3& cameraPosition); * * @brief Updates the shader light information described by cameraPosition * * @author <NAME> * @date 12/09/2021 * * @param cameraPosition The camera position. */ virtual void UpdateShaderLightInfo(const glm::vec3& cameraPosition); /** * @fn virtual void Light::CheckDistance(int distance); * * @brief Check distance * * @author <NAME> * @date 12/09/2021 * * @param distance The distance. */ virtual void CheckDistance(int distance); private: /** * @fn inline std::string Light::GetTypeAsString() * * @brief Gets type as string * * @author <NAME> * @date 12/09/2021 * * @returns The type as string. */ inline std::string GetTypeAsString() { switch (m_Type) { case LightType::Directional: return std::string("Directional"); case LightType::Point: return std::string("Point"); case LightType::Spot: return std::string("Spot"); default: return std::string("Light"); } } /** @brief The direction */ glm::vec3 m_Direction = glm::vec3(-0.2f, -1.0f, -0.3f); /** @brief The ambient */ glm::vec3 m_Ambient = glm::vec3(0.2f, 0.2f, 0.2f); /** @brief The diffuse */ glm::vec3 m_Diffuse = glm::vec3(0.5f, 0.5f, 0.5f); /** @brief The specular */ glm::vec3 m_Specular = glm::vec3(1.0f, 1.0f, 1.0f); /** @brief The position */ glm::vec3 m_Position = glm::vec3(0.0f); /** @brief The color */ glm::vec4 m_Color = glm::vec4(1.0f); /** @brief The distance */ int m_Distance = 7; /** @brief The constant */ float m_Constant = 1.0f; /** @brief The linear */ float m_Linear = 0.09f; /** @brief The quadratic */ float m_Quadratic = 0.032f; /** @brief The cut off */ float m_CutOff = glm::cos(glm::radians(12.5f)); /** @brief The intensity */ float m_Intensity = 1.0f; /** @brief The type */ LightType m_Type = LightType::Directional; /** @brief Information describing the shader light */ ShaderLightInformation m_ShaderLightInformation = ShaderLightInformation(); /** @brief True if is scene light, false if not */ bool m_IsSceneLight = false; friend class Scene; friend class Renderer; friend class EditorUI; friend class Serializer; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Application.h
#pragma once #include <queue> #include "TNAH/Core/Core.h" #include "TNAH/Core/Window.h" #include "TNAH/Events/ApplicationEvent.h" #include "TNAH/Layers/LayerStack.h" #include "TNAH/Layers/UI.h" #include "Timestep.h" #include "TNAH/Layers/ImGuiLayer.h" #include "TNAH/Renderer/Shader.h" #include "TNAH/Renderer/Renderer.h" #include "TNAH/Scene/SceneCamera.h" #include "TNAH/Physics/PhysicsTimestep.h" /** * @fn int main(int argc, char** argv); * * @brief Main entry-point for this application * * @author <NAME> * @date 7/09/2021 * * @param argc The number of command-line arguments provided. * @param argv An array of command-line argument strings. * * @returns Exit-code for the process - 0 for success, else an error code. */ int main(int argc, char** argv); /** * @namespace tnah {} * * @brief Main TNAH namespace * */ namespace tnah { class Scene; #define BIND_EVENT_FN(x) std::bind(&tnah::Application::x, this, std::placeholders::_1) /** * @class Application * * @brief A base Application class. * * @author <NAME> * @date 10/09/2021 */ class Application { public: /** * @fn Application::Application(const std::string& name = "TNAH App"); * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param name (Optional) The name of the application. */ Application(const std::string& name = "TNAH App"); /** * @fn virtual Application::~Application(); * * @brief Destructor * * @author <NAME> * @date 10/09/2021 */ virtual ~Application(); /** * @fn virtual void Application::Run(); * * @brief Runs this object * * @author <NAME> * @date 10/09/2021 */ virtual void Run(); /** * @fn virtual void Application::OnEvent(Event& e); * * @brief Executes the 'event' action * * @author <NAME> * @date 10/09/2021 * * @param [in,out] e an Event to process. */ virtual void OnEvent(Event& e); /** * @fn void Application::PushLayer(Layer* layer); * * @brief Pushes a layer * * @author <NAME> * @date 10/09/2021 * * @param [in,out] layer If non-null, the layer. */ void PushLayer(Layer* layer); /** * @fn void Application::PushOverlay(Layer* overlay); * * @brief Pushes an overlay * * @author <NAME> * @date 10/09/2021 * * @param [in,out] overlay If non-null, the overlay. */ void PushOverlay(Layer* overlay); /** * @fn void Application::Close(); * * @brief Closes this object * * @author <NAME> * @date 10/09/2021 */ void Close(); inline static Application& Get() { return *s_Instance; } /** * @fn inline Window& Application::GetWindow() * * @brief Gets the window * * @author <NAME> * @date 10/09/2021 * * @returns The window. */ inline Window& GetWindow() { return *m_Window; } /** * @fn static std::pair<std::string, int> Application::OpenFileFromBrowser(); * * @brief Opens file from browser * * @author <NAME> * @date 10/09/2021 * * @returns A std::pair&lt;std::string,int&gt; */ static std::pair<std::string, int> OpenFileFromBrowser(); /** * @fn static std::pair<std::string, int> Application::OpenAudioFromBrowser(); * * @brief Opens audio from browser * * @author <NAME> * @date 10/09/2021 * * @returns A std::pair&lt;std::string,int&gt; */ static std::pair<std::string, int> OpenAudioFromBrowser(); /** * @fn static std::pair<std::string, int> Application::OpenMeshFromBrowser(); * * @brief Opens mesh from browser * * @author <NAME> * @date 10/09/2021 * * @returns A std::pair&lt;std::string,int&gt; */ static std::pair<std::string, int> OpenMeshFromBrowser(); /** * @fn static std::pair<std::string, int> Application::SaveFileAs(const char* fileName); * * @brief Saves a file * * @author <NAME> * @date 10/09/2021 * * @param fileName Filename of the file. * * @returns A std::pair&lt;std::string,int&gt; */ static std::pair<std::string, int> SaveFileAs(const char* fileName); static void LogPush(LogText log); static std::deque<LogText> GetLogQueue(); /** * @fn bool Application::CheckEditor() const * * @brief Determines if the editor if active * * @author <NAME> * @date 10/09/2021 * * @returns True if it succeeds, false if it fails. */ bool CheckEditor() const { return m_IsEditor; } /** * @fn void Application::SetEditorMode(const bool& isEditor) * * @brief Sets editor mode * * @author <NAME> * @date 10/09/2021 * * @param isEditor True if is editor, false if not. */ void SetEditorMode(const bool& isEditor) { m_IsEditor = isEditor; } bool& GetDebugModeStatus() { return m_DebugModeEnabled; } void SetDebugStatusChange() { m_DebugModeToggled = true; } private: /** * @fn bool Application::OnWindowClose(WindowCloseEvent& e); * * @brief Executes the 'window close' action * * @author <NAME> * @date 10/09/2021 * * @param [in,out] e A WindowCloseEvent to process. * * @returns True if it succeeds, false if it fails. */ bool OnWindowClose(WindowCloseEvent& e); /** * @fn bool Application::OnWindowResize(WindowResizeEvent& e); * * @brief Executes the 'window resize' action * * @author <NAME> * @date 10/09/2021 * * @param [in,out] e A WindowResizeEvent to process. * * @returns True if it succeeds, false if it fails. */ bool OnWindowResize(WindowResizeEvent& e); /** * @fn bool Application::OnMonitorResolutionChange(MonitorResolutionChangeEvent& e); * * @brief Executes the 'monitor resolution change' action * * @author <NAME> * @date 10/09/2021 * * @param [in,out] e A MonitorResolutionChangeEvent to process. * * @returns True if it succeeds, false if it fails. */ bool OnMonitorResolutionChange(MonitorResolutionChangeEvent& e); /** * @fn void Application::CheckDebugModeStatus() * * @brief Checks the status of the application and if in debug mode, set the logger to debuf * * @author <NAME> * @date 6/09/2021 * */ void CheckDebugModeStatus() { if(m_DebugModeEnabled && m_DebugModeToggled) { m_DebugModeToggled = false; TNAH_CORE_INFO("Debug Mode Enabled"); Log::SetLoggerDebugMode(); } else if(!m_DebugModeEnabled && m_DebugModeToggled) { m_DebugModeToggled = false; Log::SetLoggerCoreMode(); TNAH_CORE_INFO("Debug Mode Disabled"); } } private: /** @brief The window */ Scope<Window> m_Window; /** @brief True if application is running */ bool m_Running = true; /** @brief True if minimized, false if not */ bool m_Minimized = false; /** @brief Stack of layers */ LayerStack m_LayerStack = LayerStack(); /** @brief The delta time */ float m_DeltaTime = 0.0f; /** @brief The imgui layer */ ImGuiLayer* m_ImGuiLayer; /** @brief True if is editor, false if not */ bool m_IsEditor = false; bool m_DebugModeEnabled = false; bool m_DebugModeToggled = false; static std::deque<LogText> logQueue; /** @brief The pointer to the instance of the application */ static Application* s_Instance; /** * @fn friend int ::main(int argc, char** argv); * * @brief Main entry-point for this application * * @author <NAME> * @date 10/09/2021 * * @param argc The number of command-line arguments provided. * @param argv An array of command-line argument strings. * * @returns Exit-code for the process - 0 for success, else an error code. */ friend int ::main(int argc, char** argv); }; /** * @fn Application* CreateApplication(); * * @brief Creates the application * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else the new application. */ Application* CreateApplication(); }
BryceStandley/TNAH
core/src/TNAH/Renderer/GraphicsContext.h
#pragma once namespace tnah { /** * @class GraphicsContext * * @brief The graphics context * * @author <NAME> * @date 12/09/2021 */ class GraphicsContext { public: /** * @fn virtual GraphicsContext::~GraphicsContext() = default; * * @brief Defaulted destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~GraphicsContext() = default; /** * @fn virtual void GraphicsContext::Init() = 0; * * @brief Initializes this object * * @author <NAME> * @date 12/09/2021 */ virtual void Init() = 0; /** * @fn virtual void GraphicsContext::SwapBuffers() = 0; * * @brief Swap buffers * * @author <NAME> * @date 12/09/2021 */ virtual void SwapBuffers() = 0; /** * @fn static Scope<GraphicsContext> GraphicsContext::Create(void* window); * * @brief Creates a new Scope&lt;GraphicsContext&gt; * * @author <NAME> * @date 12/09/2021 * * @param [in,out] window If non-null, the window. * * @returns A Scope&lt;GraphicsContext&gt; */ static Scope<GraphicsContext> Create(void* window); }; }
BryceStandley/TNAH
core/src/TNAH/Physics/PhysicsCollision.h
<gh_stars>1-10 #pragma once #include <queue> #pragma warning(push, 0) #include <reactphysics3d/reactphysics3d.h> #pragma warning(pop) #include "Rigidbody.h" namespace tnah { class GameObject; namespace Physics { /** * @class PhysicsCollision * @brief Class to hold information about a collision * @author <NAME> * @date 06-11-2021 */ class PhysicsCollision { public: /** * @class CollisionData * @brief Internal Class to hold collision data * @author <NAME> * @date 06-11-2021 */ class CollisionData { public: /** * @brief Get the Contact Point object * @author <NAME> * @date 06-11-2021 * @return glm::vec3 */ glm::vec3 GetContactPoint() const { return m_ContactPoint; } /** * @brief Get the Contact Normal object * @author <NAME> * @date 06-11-2021 * @return glm::vec3 */ glm::vec3 GetContactNormal() const { return m_ContactNormal; } /** * @brief Get the Penetration object * @author <NAME> * @date 06-11-2021 * @return float */ float GetPenetration() const { return m_PenetrationDepth; } /** * @brief Get the Contact Positions object * @author <NAME> * @date 06-11-2021 * @return std::pair<glm::vec3, glm::vec3> */ std::pair<glm::vec3, glm::vec3> GetContactPositions() { return {m_Body1ContactPosition, m_Body2ContactPosition}; } /** * @brief Get the Game Objects object * @author <NAME> * @date 06-11-2021 * @return std::pair<GameObject*, GameObject*> */ std::pair<GameObject*, GameObject*> GetGameObjects() { return {m_Body1GameObject, m_Body2GameObject}; } /** * @brief Get the Rigid Bodies object * @author <NAME> * @date 06-11-2021 * @return std::pair<Ref<RigidBody>, Ref<RigidBody>> */ std::pair<Ref<RigidBody>, Ref<RigidBody>> GetRigidBodies() { return {m_Body1RigidBody, m_Body2RigidBody}; } private: /** * @brief Contact point of the collision * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_ContactPoint = {0,0,0}; /** * @brief Contact normal of the collision * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_ContactNormal = {0,0,0}; /** * @brief Position of body 1 on contact * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_Body1ContactPosition = {0,0,0}; /** * @brief Position of body 2 on contact * @author <NAME> * @date 06-11-2021 */ glm::vec3 m_Body2ContactPosition = {0,0,0}; /** * @brief Depth the bodies penetrated when detected * @author <NAME> * @date 06-11-2021 */ float m_PenetrationDepth = 0.0f; /** * @brief Pointer to body 1's GameObject * @author <NAME> * @date 06-11-2021 */ GameObject* m_Body1GameObject = nullptr; /** * @brief Pointer to body 2's GameObject * @author <NAME> * @date 06-11-2021 */ GameObject* m_Body2GameObject = nullptr; /** * @brief Ref to body 1's RigidBody * @author <NAME> * @date 06-11-2021 */ Ref<RigidBody> m_Body1RigidBody = nullptr; /** * @brief Ref to body 2's Rigidbody * @author <NAME> * @date 06-11-2021 */ Ref<RigidBody> m_Body2RigidBody = nullptr; friend class PhysicsCollision; }; /** * @brief Construct a new Physics Collision object * @author <NAME> * @date 06-11-2021 */ PhysicsCollision(); /** * @brief Construct a new Physics Collision object * @author <NAME> * @date 06-11-2021 */ PhysicsCollision(rp3d::CollisionCallback::ContactPair contactPair); /** * @brief Get the Total Contact Points object * @author <NAME> * @date 06-11-2021 * @return uint32_t */ uint32_t GetTotalContactPoints() const { return m_TotalContactPoints; } /** * @brief Get the Collision Data object * @author <NAME> * @date 06-11-2021 * @return std::queue<CollisionData>& */ std::queue<CollisionData>& GetCollisionData() { return m_CollisionData; } private: /** * @brief Total Contact points in the collision * @author <NAME> * @date 06-11-2021 */ uint32_t m_TotalContactPoints = 0; /** * @var m_CollisionData * * @brief A queue holding data about a collision. */ std::queue<CollisionData> m_CollisionData; }; } }
BryceStandley/TNAH
core/src/TNAH/Editor/EditorUI.h
#pragma once #include "TNAH/Scene/GameObject.h" namespace tnah { /** * @class EditorUI * * @brief An editor user interface. * * @author <NAME> * @date 7/09/2021 */ class EditorUI { public: /** * @fn static void DrawComponentProperties(GameObject& object, const bool& addComponents); * * @brief Draw component properties * * @author <NAME> * @date 7/09/2021 * * @param [in,out] object The object. * @param addComponents */ static void DrawComponentProperties(GameObject& object, const bool& addComponents); /** * @fn static bool EditorUI::DrawFloatControl(const std::string& label, float& value, float min = 0.0f, float max = 0.0f, bool readOnly = false); * * @brief Draw float control * * @author <NAME> * @author <NAME> * @author <NAME> * @date 7/09/2021 * * @param label The label. * @param [in,out] value The value. * @param min (Optional) The minimum. * @param max (Optional) The maximum. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool DrawFloatControl(const std::string& label, float& value, float min = 0.0f, float max = 0.0f, bool readOnly = false); /** * @fn static bool EditorUI::DrawVec4Control(const std::string& label, glm::vec4& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); * * @brief Draw vector 4 control * * @author <NAME>y * @date 7/09/2021 * * @param label The label. * @param [in,out] values The values. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * @param columnWidth (Optional) Width of the column. * * @returns True if it succeeds, false if it fails. */ static bool DrawVec4Control(const std::string& label, glm::vec4& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); /** * @fn static bool EditorUI::DrawVec3Control(const std::string& label, glm::vec3& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); * * @brief Draw vector 3 control * * @author <NAME> * @date 7/09/2021 * * @param label The label. * @param [in,out] values The values. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * @param columnWidth (Optional) Width of the column. * * @returns True if it succeeds, false if it fails. */ static bool DrawVec3Control(const std::string& label, glm::vec3& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); /** * @fn static bool EditorUI::DrawVec2Control(const std::string& label, glm::vec2& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); * * @brief Draw vector 2 control * * @author <NAME> * @date 7/09/2021 * * @param label The label. * @param [in,out] values The values. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * @param columnWidth (Optional) Width of the column. * * @returns True if it succeeds, false if it fails. */ static bool DrawVec2Control(const std::string& label, glm::vec2& values, bool readOnly = false, float resetValue = 0.0f, float columnWidth = 100.0f); /** * @fn static bool EditorUI::DrawTextControl(const char* label, std::string& text, bool error = false, bool readOnly = false); * * @brief Draw text control * * @author <NAME> * @date 7/09/2021 * * @param label The label. * @param [in,out] text The text. * @param error (Optional) True to error. * @param readOnly (Optional) True to read only. * * @returns True if it succeeds, false if it fails. */ static bool DrawTextControl(const char* label, std::string& text, bool error = false, bool readOnly = false); /** * @fn static bool EditorUI::Draw4ColorControl(const std::string& label, glm::vec4& value, bool readOnly, const glm::vec4& resetValue, 0 parameter5, 0 parameter6, 0} parameter7); * * @brief Draw 4 color control * * @author <NAME> * @date 7/09/2021 * * @param label The label. * @param [in,out] value The value. * @param readOnly (Optional) True to read only. * @param resetValue (Optional) The reset value. * * @returns True if it succeeds, false if it fails. */ static bool Draw4ColorControl(const std::string& label, glm::vec4& value, bool readOnly = false, const glm::vec4& resetValue = {0,0,0,0}); /** * @fn static bool EditorUI::DrawMaterialProperties(bool empty, Ref<Material> material = nullptr); * * @brief Draw material properties * * @author <NAME> * @date 7/09/2021 * * @param empty True to empty. * @param material (Optional) The material. * * @returns True if it succeeds, false if it fails. */ static bool DrawMaterialProperties(bool empty, Ref<Material> material = nullptr); /** * @fn static bool EditorUI::DrawRemoveComponentButton(const std::string& id); * * @brief Draw remove component button * * @author <NAME> * @date 7/09/2021 * * @param id The identifier. * * @returns True if it succeeds, false if it fails. */ static bool DrawRemoveComponentButton(const std::string& id); /** * @fn static bool EditorUI::DrawResetButton(const std::string& id); * * @brief Draw reset button * * @author <NAME> * @date 7/09/2021 * * @param id The identifier. * * @returns True if it succeeds, false if it fails. */ static bool DrawResetButton(const std::string& id); /** * @fn static bool EditorUI::DrawRedButton(const std::string& label); * * @brief Draw red button * * @author <NAME> * @date 7/09/2021 * * @param label The label. * * @returns True if it succeeds, false if it fails. */ static bool DrawRedButton(const std::string& label); private: /** * @fn static std::list<ComponentTypes> EditorUI::GetPossibleComponentTypes(std::vector<ComponentTypes> typesHeld); * * @brief Gets the possible component types * * @author <NAME> * @date 7/09/2021 * * @param typesHeld The types held. * * @returns ComponentVariations - A type of a given component as a enum * @note Not all ComponentTypes can be returned as some are internal types not intended for * being added at runtime. */ static std::list<ComponentVariations> GetPossibleComponentTypes(std::vector<ComponentVariations> typesHeld); /** * @fn static bool EditorUI::DrawAddComponent(GameObject& object, const std::string& searchTerm = ""); * * @brief Draw add component * * @author <NAME> * @date 7/09/2021 * * @param [in,out] object The object. * @param searchTerm (Optional) The search term. * * @returns True if it succeeds, false if it fails. */ static bool DrawAddComponent(GameObject& object, const std::string& searchTerm = ""); /** * @fn static ComponentTypes EditorUI::FindAndDrawComponentSearchTerm(std::list<ComponentTypes> typesToSearch, const std::string& searchTerm); * * @brief Finds all the components that contain the search terms and draws the component list * * @author <NAME> * @date 7/09/2021 * * @param typesToSearch The types to search. * @param searchTerm The search term. * * @returns The draw component list. */ static ComponentVariations FindAndDrawComponentSearchTerm(std::list<ComponentVariations> typesToSearch, const std::string& searchTerm); /** * @fn static ComponentTypes EditorUI::DrawComponentList(std::list<ComponentTypes> componentsToDisplay); * * @brief Draw component list * * @author <NAME> * @date 7/09/2021 * * @param componentsToDisplay The components to display. * * @returns The ComponentTypes. */ static ComponentVariations DrawComponentList(std::list<ComponentVariations> componentsToDisplay); /** * @fn static std::list<ComponentTypes> EditorUI::FindAllComponentsContaining(std::list<ComponentTypes> componentsToSearch, const std::string& term); * * @brief Searches for all components containing the given * * @author <NAME> * @date 7/09/2021 * * @param componentsToSearch The components to search. * @param term The term. * * @returns The found components containing the term. */ static std::list<ComponentVariations> FindAllComponentsContaining(std::list<ComponentVariations> componentsToSearch, const std::string& term); /** * @fn static std::list<ComponentTypes> EditorUI::FindAllSubtypesFromBaseType(std::list<ComponentTypes> componentsToSearch, const ComponentCategory& category); * * @brief Searches for all components containing the given * * @author <NAME> * @date 7/09/2021 * * @param componentsToSearch The components to search. * @param category The component category to find. * * @returns The found components within the category. */ static std::list<ComponentVariations> FindAllSubtypesFromBaseType(std::list<ComponentVariations> componentsToSearch, const ComponentCategory& category); /** * @fn static std::string EditorUI::FindStringFromComponentType(ComponentTypes type); * * @brief Finds the string that matches the given component type * * @author <NAME> * @date 7/09/2021 * * @param type The type. * * @returns The found string from component type. */ static std::string FindStringFromComponentType(ComponentVariations type); /** * @fn static std::string EditorUI::FindComponentTypeCategory(ComponentTypes type); * * @brief Searches for the component type category * * @author <NAME> * @date 7/09/2021 * * @param type The type. * * @returns The found component type category. */ static std::string FindComponentTypeCategory(ComponentVariations type); /** * @fn static bool EditorUI::AddComponentFromType(GameObject& object, ComponentTypes type); * * @brief Adds a component from type * * @author <NAME> * @date 7/09/2021 * * @param [in,out] object The object. * @param type The type. * * @returns True if it succeeds, false if it fails. */ static bool AddComponentFromType(GameObject& object, ComponentVariations type); }; }
BryceStandley/TNAH
core/src/TNAH/Renderer/Image.h
<reponame>BryceStandley/TNAH #pragma once #include "Texture.h" namespace tnah { /** * @class Image * * @brief An image class that inherits from the texture2D class * * @author <NAME> * @date 12/09/2021 */ class Image : public Texture2D { public: /** * @fn virtual Image::~Image(); * * @brief Destructor * * @author <NAME> * @date 12/09/2021 */ virtual ~Image(); /** * @fn void Image::SetData(void* data, uint32_t size) override; * * @brief Sets image data * * @author <NAME> * @date 12/09/2021 * * @param [in,out] data If non-null, the data. * @param size The size. */ void SetData(void* data, uint32_t size) override; /** * @fn void Image::Bind(uint32_t slot) const override * * @brief Binds the given slot * * @author <NAME> * @date 12/09/2021 * * @param slot The slot. */ void Bind(uint32_t slot) const override {} /** * @fn void Image::Bind() const override * * @brief Binds this object * * @author <NAME> * @date 12/09/2021 */ void Bind() const override {} /** * @fn void Image::Free() override; * * @brief Frees this object * * @author <NAME> * @date 12/09/2021 */ void Free() override; /** * @fn void Image::Free(void* data) override; * * @brief Frees the given data * * @author Bryce Standley * @date 12/09/2021 * * @param [in,out] data If non-null, the data. */ void Free(void* data) override; /** * @fn ktxTexture* Image::GetKtxData() const override; * * @brief Gets ktx data * * @author <NAME> * @date 12/09/2021 * * @returns Null if it fails, else the ktx data. */ ktxTexture* GetKtxData() const override; /** * @fn uchar8_t* Image::GetImageData() const override; * * @brief Gets image data * * @author <NAME> * @date 12/09/2021 * * @returns Null if it fails, else the image data. */ uchar8_t* GetImageData() const override; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/GameObject.h
<gh_stars>1-10 #pragma once #include <TNAH/Core/Core.h> #include "Components/Components.h" #include "Scene.h" #pragma warning(push, 0) #include <entt/entt.hpp> #pragma warning(pop) namespace tnah { /** * @class GameObject * * @brief The GameObject class is used for creating gameobjects * * @author <NAME> * @date 7/09/2021 */ class GameObject { public: /** * @fn GameObject::GameObject() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 7/09/2021 */ GameObject() = default; /** * @fn GameObject::GameObject(entt::entity id, Scene* scene) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param id The identifier. * @param [in,out] scene If non-null, the scene. */ GameObject(entt::entity id, Scene* scene) : m_EntityID(id), m_Scene(scene) { } /** * @fn GameObject::~GameObject() * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ ~GameObject() { } /** * @fn template<typename T, typename... Args> inline T& GameObject::AddComponent(Args&&... args) * * @brief Adds a component to a game object * * @tparam T Generic type parameter. * @tparam Args Type of the arguments. * @param args Variable arguments providing [in,out] The arguments. * * @returns A reference to a component. */ template<typename T, typename... Args> inline T& AddComponent(Args&&... args) { if (HasComponent<T>()) { TNAH_CORE_ASSERT(HasComponent<T>(), "GameObject already has that component!"); return GetComponent<T>(); } FindComponentTypeFromTemplate<T>(); return m_Scene->m_Registry.emplace<T>(m_EntityID, std::forward<Args>(args)...); } /** * @fn template<typename T> inline T& GameObject::GetComponent() * * @brief Gets the component of a game object * * @tparam T Generic type parameter. * * @returns The component. */ template<typename T> inline T& GetComponent() { if (!HasComponent<T>()) { TNAH_CORE_ASSERT(!HasComponent<T>(), "GameObject doesn't have that component! You need to add one with AddComponent<>(), Default component added!"); return AddComponent<T>(); } else { return m_Scene->m_Registry.get<T>(m_EntityID); } } /** * @fn template<typename T> inline bool GameObject::HasComponent() * * @brief Query if this object has component * * @tparam T Generic type parameter. * * @returns True if component, false if not. */ template<typename T> inline bool HasComponent() { return m_Scene->m_Registry.all_of<T>(m_EntityID); } /** * @fn template<typename T> inline void GameObject::RemoveComponent() * * @brief Removes the component from a game object * * @tparam T Generic type parameter. */ template<typename T> inline void RemoveComponent() { if (HasComponent<T>()) { m_Scene->m_Registry.remove<T>(m_EntityID); return; } TNAH_CORE_ASSERT(false, "GameObject doesn't have that component! You can't remove what isn't there!"); } /** * @fn inline void GameObject::Destroy() * * @brief Destroys this object * * @author <NAME> * @date 7/09/2021 */ inline void Destroy() { m_Scene->m_Registry.destroy(m_EntityID); delete this; } /** * @fn entt::entity GameObject::GetID() * * @brief Gets the entity identifier * * @author <NAME> * @date 7/09/2021 * * @returns The identifier. */ entt::entity GetID() { return m_EntityID; } /** * @fn TransformComponent& GameObject::Transform() * * @brief Gets the transform * * @author <NAME> * @date 7/09/2021 * * @returns A reference to a TransformComponent. */ TransformComponent& Transform() { return m_Scene->m_Registry.get<TransformComponent>(m_EntityID); } /** * @fn const glm::mat4& GameObject::Transform() const * * @brief Gets the transform * * @author <NAME> * @date 7/09/2021 * * @returns A reference to a const glm::mat4. */ const glm::mat4& Transform() const { return m_Scene->m_Registry.get<TransformComponent>(m_EntityID).GetTransform(); } /** * @fn operator GameObject::uint32_t () const * * @brief Cast that converts the given to an uint32_t * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator uint32_t () const { return (uint32_t)m_EntityID; } /** * @fn operator entt::entity() const * * @brief Cast that converts the given to an entity * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator entt::entity() const { return m_EntityID; } /** * @fn operator GameObject::bool() const * * @brief Cast that converts the given to a bool * * @author <NAME> * @date 7/09/2021 * * @returns The result of the operation. */ operator bool() const { return (m_EntityID != entt::null) && m_Scene; } /** * @fn bool GameObject::operator==(const GameObject& other) const * * @brief Equality operator * * @author <NAME> * @date 7/09/2021 * * @param other The other. * * @returns True if the parameters are considered equivalent. */ bool operator==(const GameObject& other) const { return m_EntityID == other.m_EntityID && m_Scene == other.m_Scene; } /** * @fn bool GameObject::operator!=(const GameObject& other) const * * @brief Inequality operator * * @author <NAME> * @date 7/09/2021 * * @param other The other. * * @returns True if the parameters are not considered equivalent. */ bool operator!=(const GameObject& other) const { return !(*this == other); } /** * @fn void GameObject::SetParentUUID(UUID parent) * * @brief Sets parent uuid * * @author <NAME> * @date 7/09/2021 * * @param parent The parent. */ void SetParentUUID(UUID parent) { GetComponent<RelationshipComponent>().ParentHandle = parent; } /** * @fn UUID GameObject::GetParentUUID() * * @brief Gets the parent uuid * * @author <NAME> * @date 7/09/2021 * * @returns The parent uuid. */ UUID GetParentUUID() { return GetComponent<RelationshipComponent>().ParentHandle; } /** * @fn std::vector<UUID>& GameObject::Children() * * @brief Gets the children * * @author <NAME> * @date 7/09/2021 * * @returns A reference to a std::vector&lt;UUID&gt; */ std::vector<UUID>& Children() { return GetComponent<RelationshipComponent>().Children; } /** * @fn bool GameObject::HasParent() * * @brief Query if this object has parent * * @author <NAME> * @date 7/09/2021 * * @returns True if parent, false if not. */ bool HasParent() { return m_Scene->FindEntityByUUID(GetParentUUID()); } /** * @fn bool GameObject::IsAncesterOf(GameObject& entity) * * @brief Is ancester of the given entity * * @author <NAME> * @date 7/09/2021 * * @param [in,out] entity The entity. * * @returns True if ancester of, false if not. */ bool IsAncesterOf(GameObject& entity) { const auto& children = Children(); if (children.size() == 0) return false; for (UUID child : children) { if (child == entity.GetUUID()) return true; } for (UUID child : children) { if (m_Scene->FindEntityByUUID(child).IsAncesterOf(entity)) return true; } return false; } /** * @fn bool GameObject::IsDescendantOf(GameObject entity) * * @brief Is descendant of the given entity * * @author <NAME> * @date 7/09/2021 * * @param entity The entity. * * @returns True if descendant of, false if not. */ bool IsDescendantOf(GameObject entity) { return entity.IsAncesterOf(*this); } /** * @fn UUID GameObject::GetUUID() * * @brief Gets the uuid * * @author <NAME> * @date 7/09/2021 * * @returns The uuid. */ UUID GetUUID() { return GetComponent<IDComponent>().ID; } /** * @fn void GameObject::SetTag(const std::string& tag); * * @brief Sets a tag * * @author <NAME> * @date 7/09/2021 * * @param tag The tag. */ void SetTag(const std::string& tag); /** * @fn std::string GameObject::GetTag(); * * @brief Gets the tag * * @author <NAME> * @date 7/09/2021 * * @returns The tag. */ std::string GetTag(); /** * @fn void GameObject::SetActive(const bool& active) * * @brief Sets whether or not the object is active * * @author <NAME> * @date 7/09/2021 * * @param active True to active, false to deactivate. */ void SetActive(const bool& active) { m_Active = active; } /** * @fn bool GameObject::IsActive() const * * @brief Query if this object is active * * @author <NAME> * @date 7/09/2021 * * @returns True if active, false if not. */ bool IsActive() const { return m_Active; } /** * @fn std::vector<ComponentTypes> GameObject::GetComponentList() const * * @brief Gets component list * * @author <NAME> * @date 7/09/2021 * * @returns The component list. */ std::vector<ComponentVariations> GetComponentList() const { return m_HeldTypes; } private: /** * @fn template<typename T> void GameObject::FindComponentTypeFromTemplate() * * @brief Searches for the first component type from template * * @tparam T Generic type parameter. */ template<typename T> void FindComponentTypeFromTemplate() { if(std::is_same_v<T, IDComponent>) { m_HeldTypes.emplace_back(ComponentVariations::ID); } if(std::is_same_v<T, TagComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Tag); } if(std::is_same_v<T, RelationshipComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Relationship); } if(std::is_same_v<T, TransformComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Transform); } if(std::is_same_v<T, CameraComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Camera); } if(std::is_same_v<T, EditorCameraComponent>) { m_HeldTypes.emplace_back(ComponentVariations::EditorCamera); } if(std::is_same_v<T, EditorComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Editor); } if(std::is_same_v<T, SkyboxComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Skybox); } if(std::is_same_v<T, LightComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Light); } if(std::is_same_v<T, TerrainComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Terrain); } if(std::is_same_v<T, MeshComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Mesh); } if(std::is_same_v<T, PlayerControllerComponent>) { m_HeldTypes.emplace_back(ComponentVariations::PlayerController); } if(std::is_same_v<T, AudioListenerComponent>) { m_HeldTypes.emplace_back(ComponentVariations::AudioListener); } if(std::is_same_v<T, AudioSourceComponent>) { m_HeldTypes.emplace_back(ComponentVariations::AudioSource); } if(std::is_same_v<T, RigidBodyComponent>) { m_HeldTypes.emplace_back(ComponentVariations::Rigidbody); } } private: /** @brief Identifier for the entity */ entt::entity m_EntityID{ entt::null }; /** @brief The scene */ Scene* m_Scene = nullptr; /** @brief True to active */ bool m_Active = true; /** @brief vector of the held types*/ std::vector<ComponentVariations> m_HeldTypes = {}; /** * @class Scene * * @brief A scene. * * @author <NAME> * @date 7/09/2021 */ friend class Scene; /** * @class SceneSerializer * * @brief An object for persisting scene data. * * @author <NAME> * @date 7/09/2021 */ friend class SceneSerializer; /** * @class ScriptEngine * * @brief A script engine. * * @author <NAME> * @date 7/09/2021 */ friend class ScriptEngine; friend class PhysicsEvents; }; }
BryceStandley/TNAH
core/src/TNAH/Core/Core.h
#pragma once #include <memory> #ifdef TNAH_PLATFORM_WINDOWS #if TNAH_DYNAMIC_LINK #ifdef TNAH_BUILD_DLL #define TNAH_API _declspec(dllexport) #else #define TNAH_API _declspec(dllimport) #endif #else #define TNAH_API #endif #else #error TNAH-Engine only supports Windows x64! #endif #define TNAH_EXPAND_MACRO(x) x #define TNAH_STRINGIFY_MACRO(x) #x #define BIT(x) (1 << x) #define TNAH_BIND_EVENTS_FN(fn) std::bind(&fn, this, std::placeholders::_1) namespace tnah { template<typename T> using Scope = std::unique_ptr<T>; template<typename T, typename ... Args> constexpr Scope<T> CreateScope(Args&& ... args) { return std::make_unique<T>(std::forward<Args>(args)...); } } #ifdef TNAH_DEBUG #if defined(TNAH_PLATFORM_WINDOWS) #define TNAH_DEBUGBREAK() __debugbreak() #elif defined(TNAH_PLATFORM_LINUX) #include <signal.h> #define TNAH_DEBUGBREAK() raise(SIGTRAP) #else #error "Platform doesn't support debugbreak yet!" #endif #define TNAH_ENABLE_ASSERTS #else #define TNAH_DEBUGBREAK() #endif #ifdef TNAH_ENABLE_ASSERTS // Alternatively we could use the same "default" message for both "WITH_MSG" and "NO_MSG" and // provide support for custom formatting by concatenating the formatting string instead of having the format inside the default message #define TNAH_INTERNAL_ASSERT_IMPL(type, check, msg, ...) { if(!(check)) { TNAH##type##ERROR(msg, __VA_ARGS__); TNAH_DEBUGBREAK(); } } #define TNAH_INTERNAL_ASSERT_WITH_MSG(type, check, ...) TNAH_INTERNAL_ASSERT_IMPL(type, check, "Assertion failed: {0}", __VA_ARGS__) #define TNAH_INTERNAL_ASSERT_NO_MSG(type, check) TNAH_INTERNAL_ASSERT_IMPL(type, check, "Assertion '{0}' failed at {1}:{2}", TNAH_STRINGIFY_MACRO(check), std::filesystem::path(__FILE__).filename().string(), __LINE__) #define TNAH_INTERNAL_ASSERT_GET_MACRO_NAME(arg1, arg2, macro, ...) macro #define TNAH_INTERNAL_ASSERT_GET_MACRO(...) TNAH_EXPAND_MACRO( TNAH_INTERNAL_ASSERT_GET_MACRO_NAME(__VA_ARGS__, TNAH_INTERNAL_ASSERT_WITH_MSG, TNAH_INTERNAL_ASSERT_NO_MSG) ) // Currently accepts at least the condition and one additional parameter (the message) being optional #define TNAH_ASSERT(...) TNAH_EXPAND_MACRO( TNAH_INTERNAL_ASSERT_GET_MACRO(__VA_ARGS__)(_, __VA_ARGS__) ) #define TNAH_CORE_ASSERT(...) TNAH_EXPAND_MACRO( TNAH_INTERNAL_ASSERT_GET_MACRO(__VA_ARGS__)(_CORE_, __VA_ARGS__) ) #else #define TNAH_ASSERT(...) #define TNAH_CORE_ASSERT(...) #endif
BryceStandley/TNAH
core/src/TNAH/Scene/Light/PointLight.h
<gh_stars>1-10 #pragma once #include "TNAH/Renderer/Light.h" namespace tnah { /**********************************************************************************************//** * @class PointLight * * @brief A point light * * @author <NAME> * @date 10/09/2021 * **************************************************************************************************/ class PointLight : public Light { public: /**********************************************************************************************//** * @fn PointLight::PointLight() * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * **************************************************************************************************/ PointLight(); /**********************************************************************************************//** * @fn PointLight::PointLight(const float& constant, const float& linear, const float& quadratic); * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param constant * @param linear * @param quadratic * * **************************************************************************************************/ PointLight(const float& constant, const float& linear, const float& quadratic); /**********************************************************************************************//** * @fn PointLight::~PointLight(); * * @brief Deconstructor * * @author <NAME> * @date 10/09/2021 * * * **************************************************************************************************/ virtual ~PointLight() {} /**********************************************************************************************//** * @fn void PointLight::SetUpLight(const float& constant, const float& linear, const float& quadratic); * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param constant * @param linear * @param quadratic * * **************************************************************************************************/ void SetUpLight(const float& constant, const float& linear, const float& quadratic); }; }
BryceStandley/TNAH
core/src/Platform/OpenGL/OpenGLBuffer.h
#pragma once #include "TNAH/Renderer/RenderingBuffers.h" namespace tnah { /** * @class OpenGLVertexBuffer * * @brief OpenGLVertexBuffer class that inherits from the VertexBuffer class * * @author <NAME> * @date 7/09/2021 */ class OpenGLVertexBuffer : public VertexBuffer { public: /** * @fn OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, uint32_t size); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 */ OpenGLVertexBuffer(); /** * @fn OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, uint32_t size); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] vertices If non-null, the vertices. * @param size The size of the buffer. */ OpenGLVertexBuffer(float* vertices, uint32_t size); /** * @fn OpenGLVertexBuffer::OpenGLVertexBuffer(void* vertices, uint32_t size); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] vertices If non-null, the vertices. * @param size The size of the buffer. */ OpenGLVertexBuffer(void* vertices, uint32_t size); /** * @fn virtual OpenGLVertexBuffer::~OpenGLVertexBuffer(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~OpenGLVertexBuffer(); /** * @fn void OpenGLVertexBuffer::Bind() const override; * * @brief Binds the buffer * * @author <NAME> * @date 7/09/2021 */ void Bind() const override; /** * @fn void OpenGLVertexBuffer::Unbind() const override; * * @brief Unbinds the buffer * * @author <NAME> * @date 7/09/2021 */ void Unbind() const override; /** * @fn const BufferLayout& OpenGLVertexBuffer::GetLayout() const override * * @brief Gets the layout of the buffer * * @author <NAME> * @date 7/09/2021 * * @returns The layout. */ const VertexBufferLayout& GetLayout() const override { return m_Layout; } /** * @fn void OpenGLVertexBuffer::SetLayout(const BufferLayout& layout) override * * @brief Sets the layout of a buffer * * @author <NAME> * @date 7/09/2021 * * @param layout The layout. */ void SetLayout(const VertexBufferLayout& layout) override { m_Layout = layout; } void SetData(uint32_t size, const void* data, DrawType type = DrawType::STATIC, TypeMode mode = TypeMode::DRAW) const override; static int GetDrawMode(DrawType type, TypeMode mode); void CreateLayout(uint32_t location, BufferElement element, uint32_t stride) override; public: void DisableLayout(uint32_t location) override; private: /** @brief Identifier for the renderer */ uint32_t m_RendererID; /** @brief The buffer layout */ VertexBufferLayout m_Layout; }; /** * @class OpenGLIndexBuffer * * @brief OpenGLIndexBuffer class that inherits from the IndexBuffer class. * * @author <NAME> * @date 7/09/2021 */ class OpenGLIndexBuffer : public IndexBuffer { public: /** * @fn OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t count); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param count Number of vertices. */ OpenGLIndexBuffer(uint32_t count); /** * @fn OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t* indices, uint32_t count); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] indices If non-null, the indices. * @param count Number of vertices. */ OpenGLIndexBuffer(uint32_t* indices, uint32_t count); /** * @fn OpenGLIndexBuffer::OpenGLIndexBuffer(void* indices, uint32_t count); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param [in,out] indices If non-null, the indices. * @param count Number of. */ OpenGLIndexBuffer(void* indices, uint32_t count); /** * @fn virtual OpenGLIndexBuffer::~OpenGLIndexBuffer(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~OpenGLIndexBuffer(); /** * @fn void OpenGLIndexBuffer::Bind() const override; * * @brief Binds the index buffer * * @author <NAME> * @date 7/09/2021 */ void Bind() const override; /** * @fn void OpenGLIndexBuffer::Unbind() const override; * * @brief Unbinds the index buffer * * @author <NAME> * @date 7/09/2021 */ void Unbind() const override; /** * @fn uint32_t OpenGLIndexBuffer::GetCount() const override * * @brief Gets the count * * @author <NAME> * @date 7/09/2021 * * @returns The count. */ uint32_t GetCount() const override { return m_Count; } int GetDataType() const override; private: IndexBufferDataType m_DataType; /** @brief Identifier for the renderer */ uint32_t m_RendererID; /** @brief Number of */ uint32_t m_Count; }; /** * @class OpenGLFramebuffer * * @brief An OpenGLFrameBuffer class that inherits from the FrameBuffer base class * * @author <NAME> * @date 7/09/2021 */ class OpenGLFramebuffer : public Framebuffer { public: /** * @fn OpenGLFramebuffer::OpenGLFramebuffer(const FramebufferSpecification& spec, uint32_t colorAttachments = 1, uint32_t depthAttachments = 1); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * @param colorAttachments (Optional) The color attachments. * @param depthAttachments (Optional) The depth attachments. */ OpenGLFramebuffer(const FramebufferSpecification& spec, uint32_t colorAttachments = 1, uint32_t depthAttachments = 1); /** * @fn OpenGLFramebuffer::OpenGLFramebuffer(const FramebufferSpecification& spec, uint32_t colorAttachments, std::vector<ColorAttachmentSpecs> colorSpecs); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * @param colorAttachments The color attachments. * @param colorSpecs The color specs. */ OpenGLFramebuffer(const FramebufferSpecification& spec, uint32_t colorAttachments, std::vector<ColorAttachmentSpecs> colorSpecs); /** * @fn OpenGLFramebuffer::OpenGLFramebuffer(const FramebufferSpecification& spec, const RenderbufferSpecification& renderSpec); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * @param renderSpec Information describing the render. */ OpenGLFramebuffer(const FramebufferSpecification& spec, const RenderbufferSpecification& renderSpec); /** * @fn virtual OpenGLFramebuffer::~OpenGLFramebuffer(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~OpenGLFramebuffer(); /** * @fn void OpenGLFramebuffer::Bind(uint32_t attachmentSlot = 0) override; * * @brief Binds the given attachment slot * * @author <NAME> * @date 7/09/2021 * * @param attachmentSlot (Optional) The attachment slot. */ void Bind(uint32_t attachmentSlot = 0) override; /** * @fn void OpenGLFramebuffer::Unbind() override; * * @brief Unbinds the frameBuffer * * @author <NAME> * @date 7/09/2021 */ void Unbind() override; /** * @fn void OpenGLFramebuffer::Rebuild(const FramebufferSpecification& spec) override; * * @brief Rebuilds the given specifier * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. */ void Rebuild(const FramebufferSpecification& spec) override; /** * @fn const FramebufferSpecification& OpenGLFramebuffer::GetSpecification() const override * * @brief Gets the FrameBuffer specification * * @author <NAME> * @date 7/09/2021 * * @returns The specification. */ const FramebufferSpecification& GetSpecification() const override { return m_Specification; } /** * @fn void OpenGLFramebuffer::DrawToNext() override; * * @brief Draws to the buffer * * @author <NAME> * @date 7/09/2021 */ void DrawToNext() override; /** * @fn uint32_t OpenGLFramebuffer::GetRendererID() const override * * @brief Gets renderer identifier * * @author <NAME> * @date 7/09/2021 * * @returns The renderer identifier. */ uint32_t GetRendererID() const override { return m_RendererID; } /** * @fn uint32_t OpenGLFramebuffer::GetColorAttachment() const override * * @brief Gets color attachment * * @author <NAME> * @date 7/09/2021 * * @returns The color attachment. */ uint32_t GetColorAttachment() const override { return GetColorAttachment(0); } /** * @fn uint32_t OpenGLFramebuffer::GetColorAttachment(uint32_t attachmentNumber) const override; * * @brief Gets color attachment * * @author <NAME> * @date 7/09/2021 * * @param attachmentNumber The attachment number. * * @returns The color attachment. */ uint32_t GetColorAttachment(uint32_t attachmentNumber) const override; /** * @fn uint32_t OpenGLFramebuffer::GetTotalColorAttachments() const override * * @brief Gets total color attachments * * @author <NAME> * @date 7/09/2021 * * @returns The total color attachments. */ uint32_t GetTotalColorAttachments() const override { return (uint32_t)m_ColorAttachments.size(); } /** * @fn uint32_t OpenGLFramebuffer::GetDepthAttachmentID() const override * * @brief Gets depth attachment identifier * * @author <NAME> * @date 7/09/2021 * * @returns The depth attachment identifier. */ uint32_t GetDepthAttachmentID() const override { return GetDepthAttachmentID(0); } /** * @fn uint32_t OpenGLFramebuffer::GetDepthAttachmentID(uint32_t attachmentNumber) const override; * * @brief Gets depth attachment identifier * * @author <NAME> * @date 7/09/2021 * * @param attachmentNumber The attachment number. * * @returns The depth attachment identifier. */ uint32_t GetDepthAttachmentID(uint32_t attachmentNumber) const override; /** * @fn uint32_t OpenGLFramebuffer::GetTotalDepthAttachments() const override * * @brief Gets total depth attachments * * @author <NAME> * @date 7/09/2021 * * @returns The size of total depth attachments. */ uint32_t GetTotalDepthAttachments() const override { return (uint32_t)m_DepthAttachments.size(); } /** * @fn uint32_t OpenGLFramebuffer::GetRenderBufferID() const override * * @brief Gets render buffer identifier * * @author <NAME> * @date 7/09/2021 * * @returns The render buffer identifier. */ uint32_t GetRenderBufferID() const override { return m_Renderbuffer->GetRendererID(); } /** * @fn void OpenGLFramebuffer::SetRenderbufferSpecification(uint32_t bufferSlot, const RenderbufferSpecification& spec) override; * * @brief Sets renderbuffer specification * * @author <NAME> * @date 7/09/2021 * * @param bufferSlot The buffer slot. * @param spec The specifier. */ void SetRenderbufferSpecification(uint32_t bufferSlot, const RenderbufferSpecification& spec) override; /** * @fn void OpenGLFramebuffer::SelectDrawToBuffer(const FramebufferDrawMode& mode, uint32_t attachmentNumber) override; * * @brief Select draw to buffer mode * * @author <NAME> * @date 7/09/2021 * * @param mode The mode of the FrameBuffer. * @param attachmentNumber The attachment number. */ void SelectDrawToBuffer(const FramebufferDrawMode& mode, uint32_t attachmentNumber) override; /** * @fn int OpenGLFramebuffer::GetFormatFromSpec(const FramebufferSpecification& spec) override; * * @brief Gets format from specifier * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * * @returns The format from specifier. */ int GetFormatFromSpec(const FramebufferSpecification& spec) override; private: /** * @fn void OpenGLFramebuffer::Invalidate(uint32_t color = 1, uint32_t depth = 1, RenderbufferSpecification renderSpec = {0} ); * * @brief Resets and regenerates frame buffer with new properties * * @author <NAME> * @date 7/09/2021 * * @param color (Optional) The color. * @param depth (Optional) The depth. * @param renderSpec (Optional) Information describing the render. */ void Invalidate(uint32_t color = 1, uint32_t depth = 1, RenderbufferSpecification renderSpec = {0} ); /** @brief Identifier for the renderer */ uint32_t m_RendererID; /** @brief The specification of the framebuffer */ FramebufferSpecification m_Specification; /** @brief A vector of color specifications */ std::vector<ColorAttachmentSpecs> m_ColorSpecifications; /** @brief A vector of color attachments */ std::vector<uint32_t> m_ColorAttachments; /** @brief A vector of depth attachments */ std::vector<uint32_t> m_DepthAttachments; /** @brief A pointer to the renderbuffer */ Ref<Renderbuffer> m_Renderbuffer; /** @brief The renderbuffer specification */ RenderbufferSpecification m_RenderbufferSpecification; /** @brief The active color attachment */ uint32_t m_ActiveColorAttachment = 0; }; /** * @class OpenGLRenderBuffer * * @brief OpenGLRenderBuffer class that inherits from the RenderBuffer base class * * @author <NAME> * @date 7/09/2021 */ class OpenGLRenderBuffer : public Renderbuffer { public: /** * @fn virtual OpenGLRenderBuffer::~OpenGLRenderBuffer(); * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~OpenGLRenderBuffer(); /** * @fn OpenGLRenderBuffer::OpenGLRenderBuffer(const RenderbufferSpecification& spec); * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. */ OpenGLRenderBuffer(const RenderbufferSpecification& spec); /** * @fn uint32_t OpenGLRenderBuffer::GetRendererID() const override * * @brief Gets renderer identifier * * @author <NAME> * @date 7/09/2021 * * @returns The renderer identifier. */ uint32_t GetRendererID() const override { return m_RendererID; } /** * @fn void OpenGLRenderBuffer::Bind() override; * * @brief Binds the render buffer * * @author <NAME> * @date 7/09/2021 */ void Bind() override; /** * @fn void OpenGLRenderBuffer::Unbind() override; * * @brief Unbinds the render buffer * * @author <NAME> * @date 7/09/2021 */ void Unbind() override; /** * @fn void OpenGLRenderBuffer::Rebuild(const RenderbufferSpecification& spec) override; * * @brief Rebuilds the given specifier * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. */ void Rebuild(const RenderbufferSpecification& spec) override; /** * @fn void OpenGLRenderBuffer::AttachToFramebuffer() override; * * @brief Attaches the render buffer to framebuffer * * @author <NAME> * @date 7/09/2021 */ void AttachToFramebuffer() override; /** * @fn int OpenGLRenderBuffer::GetFormatFromSpecification(const RenderbufferSpecification& spec) override; * * @brief Gets format from specification * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * * @returns The format from specification. */ int GetFormatFromSpecification(const RenderbufferSpecification& spec) override; /** * @fn int OpenGLRenderBuffer::GetFramebufferFormatFromSpecification(const RenderbufferSpecification& spec) override; * * @brief Gets framebuffer format from specification * * @author <NAME> * @date 7/09/2021 * * @param spec The specifier. * * @returns The framebuffer format from specification. */ int GetFramebufferFormatFromSpecification(const RenderbufferSpecification& spec) override; private: /** * @fn void OpenGLRenderBuffer::Invalidate(); * * @brief Resets and regenerates frame buffer with new properties * * @author <NAME> * @date 7/09/2021 */ void Invalidate(); private: /** @brief Identifier for the renderer */ uint32_t m_RendererID; /** @brief The specification */ RenderbufferSpecification m_Specification; }; }
BryceStandley/TNAH
core/src/TNAH/Layers/ImGuiLayer.h
<reponame>BryceStandley/TNAH<filename>core/src/TNAH/Layers/ImGuiLayer.h #pragma once #include "Layer.h" #include "TNAH/Events/ApplicationEvent.h" #include "TNAH/Events/KeyEvent.h" #include "TNAH/Events/MouseEvent.h" namespace tnah { class TNAH_API ImGuiLayer : public Layer { public: /** * @fn ImGuiLayer::ImGuiLayer(); * * @brief Default constructor * * @author <NAME> * @date 10/09/2021 */ ImGuiLayer(); /** * @fn ImGuiLayer::~ImGuiLayer(); * * @brief Destructor * * @author <NAME> * @date 10/09/2021 */ ~ImGuiLayer(); /** * @fn virtual void ImGuiLayer::OnAttach() override; * * @brief Executes on attach of the layer * * @author <NAME> * @date 10/09/2021 */ virtual void OnAttach() override; /** * @fn virtual void ImGuiLayer::OnDetach() override; * * @brief Executes on imgui layer detach * * @author <NAME> * @date 10/09/2021 */ virtual void OnDetach() override; /** * @fn void ImGuiLayer::Begin(); * * @brief Begins the imgui layer * * @author <NAME> * @date 10/09/2021 */ void Begin(); /** * @fn void ImGuiLayer::End(); * * @brief Ends the layer * * @author <NAME> * @date 10/09/2021 */ void End(); /** * @fn virtual void ImGuiLayer::OnEvent(Event& event) override; * * @brief Executes on event * * @author <NAME> * @date 10/09/2021 * * @param [in,out] event The event. */ virtual void OnEvent(Event& event) override; /** * @fn virtual void ImGuiLayer::OnImGuiRender() override; * * @brief Executes on imgui render * * @author <NAME> * @date 10/09/2021 */ virtual void OnImGuiRender() override; /** * @fn void ImGuiLayer::SetDarkThemeColors(); * * @brief Sets dark theme colors * * @author <NAME> * @date 10/09/2021 */ void SetDarkThemeColors(); private: /** @brief True to block events */ bool m_BlockEvents = true; /** @brief The time */ float m_Time = 0.0f; }; }
BryceStandley/TNAH
core/src/TNAH/Layers/LayerStack.h
<gh_stars>1-10 #pragma once #include "TNAH/Core/Core.h" #include "Layer.h" #include <vector> namespace tnah { /** * @class LayerStack * * @brief The LayerStack class is used to store multiple layers, while allowing for them to be added and removed * * @author <NAME> * @date 10/09/2021 */ class LayerStack { public: /** * @fn LayerStack::LayerStack() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 */ LayerStack() = default; /** * @fn LayerStack::~LayerStack(); * * @brief Destructor * * @author <NAME> * @date 10/09/2021 */ ~LayerStack(); /** * @fn void LayerStack::PushLayer(Layer* layer); * * @brief Pushes a layer * * @author <NAME> * @date 10/09/2021 * * @param [in,out] layer If non-null, the layer. */ void PushLayer(Layer* layer); /** * @fn void LayerStack::PushOverlay(Layer* overlay); * * @brief Pushes an overlay * * @author <NAME> * @date 10/09/2021 * * @param [in,out] overlay If non-null, the overlay. */ void PushOverlay(Layer* overlay); /** * @fn void LayerStack::PopLayer(Layer* layer); * * @brief Pops(Removes) the layer described by layer * * @author <NAME> * @date 10/09/2021 * * @param [in,out] layer If non-null, the layer. */ void PopLayer(Layer* layer); /** * @fn void LayerStack::PopOverlay(Layer* overlay); * * @brief Pops(Remove) the overlay described by overlay * * @author <NAME> * @date 10/09/2021 * * @param [in,out] overlay If non-null, the overlay. */ void PopOverlay(Layer* overlay); /** * @fn std::vector<Layer*>::iterator LayerStack::begin() * * @brief Gets the beginning of the iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::iterator. */ std::vector<Layer*>::iterator begin() { return m_Layers.begin(); } /** * @fn std::vector<Layer*>::iterator LayerStack::end() * * @brief Gets the end of the iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::iterator. */ std::vector<Layer*>::iterator end() { return m_Layers.end(); } /** * @fn std::vector<Layer*>::reverse_iterator LayerStack::rbegin() * * @brief Gets the rbegin of the reverse iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::reverse_iterator. */ std::vector<Layer*>::reverse_iterator rbegin() { return m_Layers.rbegin(); } /** * @fn std::vector<Layer*>::reverse_iterator LayerStack::rend() * * @brief Gets the rend of the reverse iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::reverse_iterator. */ std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); } /** * @fn std::vector<Layer*>::const_iterator LayerStack::begin() const * * @brief Gets the begin of the iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::const_iterator. */ std::vector<Layer*>::const_iterator begin() const { return m_Layers.begin(); } /** * @fn std::vector<Layer*>::const_iterator LayerStack::end() const * * @brief Gets the end of the iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::const_iterator. */ std::vector<Layer*>::const_iterator end() const { return m_Layers.end(); } /** * @fn std::vector<Layer*>::const_reverse_iterator LayerStack::rbegin() const * * @brief Gets the rbegin of the reverse iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::const_reverse_iterator. */ std::vector<Layer*>::const_reverse_iterator rbegin() const { return m_Layers.rbegin(); } /** * @fn std::vector<Layer*>::const_reverse_iterator LayerStack::rend() const * * @brief Gets the rend of the reverse iterator * * @author <NAME> * @date 10/09/2021 * * @returns Null if it fails, else a std::vector&lt;Layer*&gt;::const_reverse_iterator. */ std::vector<Layer*>::const_reverse_iterator rend() const { return m_Layers.rend(); } private: std::vector<Layer*> m_Layers; unsigned int m_LayerInsertIndex = 0; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Light/SpotLight.h
#pragma once #include "TNAH/Renderer/Light.h" namespace tnah { /** * * * \brief Spot light type * * \author <NAME> * \date 13/9/2021 */ class SpotLight : public Light { public: /** * * \fn void SpotLight * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * * */ SpotLight(); /** * * \fn void SpotLight * * \brief Constructor * * \author <NAME> * \date 13/9/2021 * * \param cutoff * * */ SpotLight(const float& cutoff); /** * * \fn void ~SpotLight * * \brief Deconstructor * * \author <NAME> * \date 13/9/2021 * * * */ virtual ~SpotLight() {} /** * * \fn void SetUpLight * * \brief Light Set up * * \author <NAME> * \date 13/9/2021 * * \param cutoff * * */ void SetUpLight(const float& cutoff); }; }
BryceStandley/TNAH
core/src/TNAH/Core/Window.h
<filename>core/src/TNAH/Core/Window.h #pragma once #include <tnahpch.h> #include "TNAH/Events/Event.h" namespace tnah { struct WindowProps { /** @brief The title */ std::string Title; /** @brief The width */ unsigned int Width; /** @brief The height */ unsigned int Height; /** * @fn WindowProps(const std::string& title = "TNAH-Engine", unsigned int width = 1280, unsigned int height = 720) * * @brief Constructor * * @author <NAME> * @date 7/09/2021 * * @param title (Optional) The title. * @param width (Optional) The width. * @param height (Optional) The height. */ WindowProps(const std::string& title = "TNAH-Engine", unsigned int width = 1280, unsigned int height = 720) : Title(title), Width(width), Height(height) { } }; /** * @class Window * * @brief An abstract window class that provides the virtual function defintions required to create a window * * @author <NAME> * @date 7/09/2021 */ class Window { public: /** @brief The event callback function */ using EventCallbackFn = std::function<void(Event&)>; /** * @fn virtual Window::~Window() * * @brief Destructor * * @author <NAME> * @date 7/09/2021 */ virtual ~Window() {} /** * @fn virtual void Window::OnUpdate() = 0; * * @brief Executes the 'update' action * * @author <NAME> * @date 7/09/2021 */ virtual void OnUpdate() = 0; /** * @fn virtual unsigned int Window::GetWidth() const = 0; * * @brief Gets the width * * @author <NAME> * @date 7/09/2021 * * @returns The width. */ virtual unsigned int GetWidth() const = 0; /** * @fn virtual unsigned int Window::GetHeight() const = 0; * * @brief Gets the height * * @author <NAME> * @date 7/09/2021 * * @returns The height. */ virtual unsigned int GetHeight() const = 0; /** * @fn virtual void Window::SetEventCallback(const EventCallbackFn& callback) = 0; * * @brief sets the event callback to the callback given as a parameter * * @author <NAME> * @date 7/09/2021 * * @param callback The callback. */ virtual void SetEventCallback(const EventCallbackFn& callback) = 0; /** * @fn virtual void Window::SetVSync(bool enabled) = 0; * * @brief Sets v synchronize * * @author <NAME> * @date 7/09/2021 * * @param enabled True to enable, false to disable. */ virtual void SetVSync(bool enabled) = 0; /** * @fn virtual bool Window::IsVSync() const = 0; * * @brief Query if this object is v synchronize * * @author <NAME> * @date 7/09/2021 * * @returns True if v synchronize, false if not. */ virtual bool IsVSync() const = 0; /** * @fn virtual bool Window::IsFullscreen() const = 0; * * @brief Query if this object is fullscreen * * @author <NAME> * @date 7/09/2021 * * @returns True if fullscreen, false if not. */ virtual bool IsFullscreen() const = 0; /** * @fn virtual void Window::ToggleFullScreen(const bool& enabled) = 0; * * @brief Toggle full screen * * @author <NAME> * @date 7/09/2021 * * @param enabled True to enable, false to disable. */ virtual void ToggleFullScreen(const bool& enabled) = 0; /** * @fn virtual void Window::SetScreenResolution(const uint32_t& width, const uint32_t& height) = 0; * * @brief Sets screen resolution * * @author <NAME> * @date 7/09/2021 * * @param width The width. * @param height The height. */ virtual void SetScreenResolution(const uint32_t& width, const uint32_t& height) = 0; /** * @fn virtual void* Window::GetNativeWindow() const = 0; * * @brief Gets native window * * @author <NAME> * @date 7/09/2021 * * @returns Null if it fails, else the native window. */ virtual void* GetNativeWindow() const = 0; /** * @fn virtual void Window::SetCursorDisabled(bool disable) = 0; * * @brief Sets cursor disabled * * @author <NAME> * @date 7/09/2021 * * @param disable True to disable, false to enable. */ virtual void SetCursorDisabled(bool disable) = 0; /** * @fn static Scope<Window> Window::Create(const WindowProps& props = WindowProps()); * * @brief Creates a new Scope&lt;Window&gt; * * @author <NAME> * @date 7/09/2021 * * @param props (Optional) The properties. * * @returns A Scope&lt;Window&gt; */ static Scope<Window> Create(const WindowProps& props = WindowProps()); }; }
BryceStandley/TNAH
core/src/Platform/IrrKlang/Klang.h
#pragma once #include "TNAH/Audio/AudioAPI.h" #pragma warning(push, 0) #include <IrrKlang/irrKlang.h> #include <vector> #include <unordered_map> #include <string> #pragma warning(pop) typedef std::pair<u_int, irrklang::ISoundSource*> AudioSourcePair; typedef std::unordered_map<std::string, irrklang::ISoundSource*> AudioSources; typedef std::vector<irrklang::ISound*> AudioPlaying; typedef std::vector<std::string> AudioKeys; namespace tnah { /** * @class Klang * * @brief A derived IrrKlang class that inherits from the base class AudioAPI. Responsible for the in-game audio. * * @author <NAME> * @date 6/09/2021 */ class Klang final : public AudioAPI { public: /** * @fn Klang(); * * @brief Default constructor * * @author <NAME> * @date 6/09/2021 */ Klang(); /** * @fn ~Klang(); * * @brief Destructor * * @author <NAME> * @date 6/09/2021 */ virtual ~Klang(); /** * @fn bool SetListener(TransformComponent &transform) const override; * * @brief Sets a audio listeners position to the transform * * @author <NAME> * @date 6/09/2021 * * @param [in,out] transform The transform component. * * @returns True if it succeeds, false if it fails. */ bool SetListener(TransformComponent &transform) const override; /** * @fn bool AddAudioSource(AudioSourceComponent&sound) override; * * @brief Adds an audio source to the audio source unordered_map, returns false if it doesn't load and returns true if loads in or is already loaded in. * * @author <NAME> * @date 6/09/2021 * * @param [in,out] sound The sound component. * * @returns True if it succeeds, false if it fails. */ bool AddAudioSource(AudioSourceComponent&sound) override; /** * @fn bool UpdateAudioSource(AudioSourceComponent&sound) override; * * @brief Updates the audio source file * * @author <NAME> * @date 6/09/2021 * * @param [in,out] sound The sound component. * * @returns True if it succeeds, false if it fails. */ bool UpdateAudioSource(AudioSourceComponent&sound) override; /** * @fn void OnUpdate() override; * * @brief Updates the audio class * * @author <NAME> * @date 7/09/2021 */ void OnUpdate() override; /** * @fn void UpdateSound(AudioSourceComponent& sound, TransformComponent &transform) override; * * @brief Updates the sound * * @author <NAME> * @date 7/09/2021 * * @param [in,out] sound The sound component. * @param [in,out] transform The transform component. */ void UpdateSound(AudioSourceComponent& sound, TransformComponent &transform) override; /** * @fn bool Active() const override * * @brief Checks if sound engine is active * * @author <NAME> * @date 7/09/2021 * * @returns True if it succeeds, false if it fails. */ bool Active() const override {return m_Engine;} /** * @fn void Clear() override; * * @brief Clears this object to its blank/initial state * * @author <NAME> * @date 6/09/2021 */ void Clear() override; private: /** * @fn bool PlayAudioSource(AudioSourceComponent& sound, TransformComponent &transform); * * @brief Plays the audio source if returned bool is true, doesn't if false * * @author <NAME> * @date 6/09/2021 * * @param [in,out] sound The sound component. * @param [in,out] transform The transform component. * * @returns True if it succeeds, false if it fails. */ bool PlayAudioSource(AudioSourceComponent& sound, TransformComponent &transform); /** @brief Represents the audio source */ AudioSources m_Source; /** @brief Represents the playing of the audio source */ AudioPlaying m_Playing; /** @brief The audio keys */ AudioKeys m_Keys; /** @brief A pointer to the sound engine */ irrklang::ISoundEngine* m_Engine; }; };
BryceStandley/TNAH
core/src/TNAH/Physics/CollisionDetectionEngine.h
<filename>core/src/TNAH/Physics/CollisionDetectionEngine.h #pragma once #include "PhysicsCollision.h" #include "TNAH/Physics/PhysicsTimestep.h" #include <queue> namespace tnah { namespace Physics { /** * @class CollisionDetectionEngine * @brief Class to wrap and construct collision information * @author <NAME> * @date 06-11-2021 */ class CollisionDetectionEngine : public RefCounted { public: /** * @brief Creates a Ref to the collision detection engine * @author <NAME> * @date 06-11-2021 * @return Ref<CollisionDetectionEngine> */ static Ref<CollisionDetectionEngine> Create(); /** * @brief Construct a new Collision Detection Engine object * @author <NAME> * @date 06-11-2021 */ CollisionDetectionEngine(); /** * @brief Fixed update loop function to update the physics world * @author <NAME> * @date 06-11-2021 */ void FixedUpdate(rp3d::PhysicsWorld* physicsWorld, PhysicsTimestep physTime); /** * @brief Get the Current Collisions object * @author <NAME> * @date 06-11-2021 * @return std::queue<PhysicsCollision>& */ std::queue<PhysicsCollision>& GetCurrentCollisions() { return m_CurrentCollisions; } /** * @brief Registers a collision into the collision queue * @author <NAME> * @date 06-11-2021 */ void RegisterCollision(PhysicsCollision collision) { m_CurrentCollisions.push(collision); } private: /** * @var m_CurrentCollisions * @brief Queue of current collisions * @author <NAME> * @date 06-11-2021 */ std::queue<PhysicsCollision> m_CurrentCollisions; }; } }
BryceStandley/TNAH
core/src/TNAH.h
#pragma once //This Header MUST be included within the same file as applications derived tnah::Application class is defined #include "TNAH-App.h" // --- Entry Point --- // #include "TNAH/Core/EntryPoint.h"
BryceStandley/TNAH
core/src/TNAH-App.h
#pragma once //This header is a combined header of all components of the engine // Use this header in any applications that require access to structures and classes // within the engine // NOTE any application needs to #include <TNAH.h> in their main Application cpp file // to enable the entry point of the application, not doing this will result in build errors //To include in all applications that use the TNAH-Engine! #include "TNAH/Core/Core.h" // --- TNAH Engine Components --- // #include "TNAH/Core/Application.h" #include "TNAH/Core/Log.h" #include "TNAH/Core/FileStructures.h" #include "TNAH/Core/Input.h" #include "TNAH/Core/KeyCodes.h" #include "TNAH/Core/MouseCodes.h" #include "TNAH/Core/Math.h" #include "TNAH/Core/FileManager.h" #include "TNAH/Core/Singleton.h" #include "TNAH/Core/Timestep.h" #include "TNAH/Physics/PhysicsTimestep.h" #include "TNAH/Layers/Layer.h" #include "TNAH/Layers/ImGuiLayer.h" #include "TNAH/Scene/Components/Components.h" #include "TNAH/Scene/Scene.h" #include "TNAH/Scene/GameObject.h" #include "TNAH/Scene/Light/DirectionalLight.h" #include "TNAH/Scene/Light/PointLight.h" #include "TNAH/Scene/Light/SpotLight.h" #include "TNAH/Scene/SceneCamera.h" #include "TNAH/Renderer/Renderer.h" #include "TNAH/Renderer/RenderCommand.h" #include "TNAH/Renderer/RenderingBuffers.h" #include "TNAH/Renderer/Shader.h" #include "TNAH/Renderer/VertexArray.h" // Editor #include "TNAH/Editor/EditorUI.h" //Audio #include "TNAH/Audio/Audio.h"
BryceStandley/TNAH
core/src/tnahpch.h
#pragma once #define _CRT_SECURE_NO_WARNINGS #pragma warning(push, 0) // Disable warnings for all files within the push/pop #ifdef TNAH_PLATFORM_WINDOWS #include <Windows.h> #endif // --- TNAH Precompiled Header File --- // #include <memory> #include <vector> #include <string> #include <array> #include <unordered_map> #include <functional> #include <algorithm> #include <random> #include <fstream> // --- 3rd Party headers --- // #include <glm/glm.hpp> #pragma warning(pop) // Disable warnings for all files within the push/pop // --- Our Headers that don't change --- // #include "TNAH/Core/Core.h" #include "TNAH/Core/Ref.h" #include "TNAH/Core/Log.h" #include "TNAH/Core/Utility.h" #include "TNAH/Core/Math.h"
BryceStandley/TNAH
core/src/TNAH/Scene/Components/AudioComponents.h
#pragma once #include "TNAH/Core/Core.h" #include "TNAH/Core/FileStructures.h" #include "ComponentIdentification.h" namespace tnah { /**********************************************************************************************//** * @class AudioSourceComponent * * @brief An audio source component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class AudioSourceComponent { public: /**********************************************************************************************//** * @fn AudioSourceComponent::AudioSourceComponent(Resource file = {"defaultsoundfile.wav"}, float minDistance = 1.0f, float volume = 1.0f, bool threeDim = true, bool loop = false) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param file (Optional) The file. * @param minDistance (Optional) The minimum distance. * @param volume (Optional) The volume. * @param threeDim (Optional) True to three dim. * @param loop (Optional) True to loop. **************************************************************************************************/ AudioSourceComponent(Resource file = {"defaultsoundfile.wav"}, float minDistance = 1.0f, float volume = 0.5f, bool threeDim = true, bool loop = false) : m_MinDistance(minDistance), m_Volume(volume), m_Loop(loop), m_SourceReference(0), m_PlayReference(0), m_Playing(false), m_Loaded(false), m_Shoot(false), m_3D(threeDim),m_StartLoad(true), m_Paused(false) {m_File = file;} /**********************************************************************************************//** * @fn bool AudioSourceComponent::GetStartLoad() const * * @brief Gets start load * * @author Chris * @date 10/09/2021 * * @returns True if it succeeds, false if it fails. **************************************************************************************************/ bool GetStartLoad() const { return m_StartLoad; } /**********************************************************************************************//** * @fn void AudioSourceComponent::SetStartLoad(const bool b) * * @brief Sets start load * * @author Chris * @date 10/09/2021 * * @param b True to b. **************************************************************************************************/ void SetStartLoad(const bool b) {m_StartLoad = b;} /** @brief Source reference */ int m_SourceReference; /** @brief The play reference */ int m_PlayReference; /** @brief The minimum distance */ float m_MinDistance; /** @brief The volume */ float m_Volume; /** @brief True to loop */ bool m_Loop; /** @brief True to playing */ bool m_Playing; /** @brief True if paused */ bool m_Paused; /** @brief True if the data was loaded */ bool m_Loaded; /** @brief True to shoot */ bool m_Shoot; /** @brief True if 3D */ bool m_3D; /** @brief The file */ Resource m_File; private: /** @brief True to start load */ bool m_StartLoad; friend class EditorUI; inline static std::string s_SearchString = "audio source component"; inline static ComponentTypes s_Types = { {ComponentVariations::AudioSource}, {{ComponentCategory::Audio}} }; }; /**********************************************************************************************//** * @class AudioListenerComponent * * @brief An audio listener component. * * @author Chris * @date 10/09/2021 **************************************************************************************************/ class AudioListenerComponent { public: /**********************************************************************************************//** * @fn AudioListenerComponent::AudioListenerComponent(bool active = false) * * @brief Constructor * * @author Chris * @date 10/09/2021 * * @param active (Optional) True to active. **************************************************************************************************/ AudioListenerComponent(bool active = false) : m_ActiveListing(active) {} /** @brief True to active listing */ bool m_ActiveListing; private: friend class EditorUI; inline static std::string s_SearchString = "audio listener component"; inline static ComponentTypes s_Types = { {ComponentVariations::AudioListener}, {{ComponentCategory::Audio}} }; }; }
BryceStandley/TNAH
core/src/TNAH/Scene/Components/LightComponents.h
#pragma once #include "TNAH/Core/Core.h" #include "TNAH/Renderer/Light.h" #include "TNAH/Scene/Light/DirectionalLight.h" #include "TNAH/Scene/Light/PointLight.h" #include "TNAH/Scene/Light/SpotLight.h" #include "ComponentIdentification.h" namespace tnah { /**********************************************************************************************//** * @class LightComponent * * @brief A light component. * * @author <NAME> * @date 10/09/2021 **************************************************************************************************/ class LightComponent { public: /** @brief The light */ Ref<Light> Light; /**********************************************************************************************//** * @fn LightComponent::LightComponent() = default; * * @brief Defaulted constructor * * @author <NAME> * @date 10/09/2021 **************************************************************************************************/ LightComponent() = default; /**********************************************************************************************//** * @fn LightComponent::LightComponent(const LightComponent& other) = default; * * @brief Defaulted copy constructor * * @author <NAME> * @date 10/09/2021 * * @param other The other. **************************************************************************************************/ LightComponent(const LightComponent& other) = default; /**********************************************************************************************//** * @fn LightComponent::LightComponent(const tnah::Light::LightType& type) * * @brief Constructor * * @author <NAME> * @date 10/09/2021 * * @param type The type. **************************************************************************************************/ LightComponent(const tnah::Light::LightType& type) { Light = Light::Create(type); } /**********************************************************************************************//** * @fn void LightComponent::SetDirectional(const glm::vec3& direction, const glm::vec3& ambient,const glm::vec3& diffuse, const glm::vec3& specular) * * @brief Sets a directional * * @author <NAME> * @date 10/09/2021 * * @param direction The direction. * @param ambient The ambient. * @param diffuse The diffuse. * @param specular The specular. **************************************************************************************************/ void SetDirectional(const glm::vec3& direction, const glm::vec3& ambient,const glm::vec3& diffuse, const glm::vec3& specular) { Light = Light::CreateDirectional(direction, ambient, diffuse, specular); } /**********************************************************************************************//** * @fn void LightComponent::SetPoint(const float& constant, const float& linear, const float& quadratic) * * @brief Sets a point * * @author <NAME> * @date 10/09/2021 * * @param constant The constant. * @param linear The linear. * @param quadratic The quadratic. **************************************************************************************************/ void SetPoint(const float& constant, const float& linear, const float& quadratic) { Light = Light::CreatePoint(constant, linear, quadratic); } /**********************************************************************************************//** * @fn void LightComponent::SetSpot(const float& cutoff) * * @brief Sets a spot * * @author <NAME> * @date 10/09/2021 * * @param cutoff The cutoff. **************************************************************************************************/ void SetSpot(const float& cutoff) { Light = Light::CreateSpot(cutoff); } /**********************************************************************************************//** * @fn operator const Ref<tnah::Light> () const * * @brief Gets the light> * * @author <NAME> * @date 10/09/2021 * * @tparam tnah::Light Type of the tnah light. * * @returns A const. **************************************************************************************************/ operator const Ref<tnah::Light> () const { return Light; } private: friend class EditorUI; inline static std::string s_SearchString = "light component"; inline static ComponentTypes s_Types = { {ComponentVariations::Light}, {{ComponentCategory::Core, ComponentCategory::Lighting}} }; }; }