collapse collapse

* Who's Online

  • Dot Guests: 51
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Celestialkey

Pages: [1] 2 3 4 5 6 ... 124
1
Projects / Re: srchub - free source code hosting
« on: November 27, 2015, 08:51:42 AM »

I usually don't bring up old threads but I do want to post some updates.

  • OTP has been integrated
  • Exporting a project has been implemented

The service has been moved to gandi's infrastructure so now I can support largish files but srchub also supports the ability to link files offsite


Still no import feature? Sounds like a pretty big flaw if so.

2
Misc / Interesting Look into the ALU
« on: April 28, 2015, 01:10:51 PM »
I found a very good video explaining how computers use the basic transistor component to do multiplication. I'm currently working on a project for college that requires something along these lines. Figured I'd share it since it was such a good video.


3
Tutorial Support / Re: A PHP Solution
« on: March 05, 2015, 09:04:41 PM »

Next up is how to use php to execute a batch file on my system. I wrote a small batch that essentially executes another program for FastDL sync (as gmod caps DL at 20kb/s) but this program can take a while to complete compressing and copying files. Does something like system("C:\program.bat") work? This particular program requires me to press enter when it is finished, is there a way I could get a program to do this for me? And would the program have to hold up the entire PHP while it takes its 10+ minutes to complete? Any ways around this if it is the case? I feel like all the things I'm trying to do have horrible security concerns.

Would I be better off writing something to run on the system rather than attempting to do all this through php? I want these functions to be accessible to the web, so that I can use them.

Due to the inherent nature of php and what it is designed to do, your best option would be to write an extension for it if you want it to communicate with an outside application. I'm not very familiar with the process, but the link below is a good starting spot. What your are trying to do goes against the SOP for php, if you half-ass it and work through lots of different "work arounds" you will end up creating a convoluted system that would inherently be far more vulnerable to outside hacks, abuse or internal errors than you would doing it via an extension.

http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/

4
Tutorial Support / Re: My First Program
« on: February 19, 2015, 09:55:11 PM »
The code looks good. It is pretty solid. The only suggestions I can make that Nate didn't already cover are pretty much opinionated, so here are some of my opinions.

Lets start here...
Code: C++
  1.  
  2. void printall()
  3. {
  4.     for( vector<string>::const_iterator i = data.begin(); i != data.end(); i++)
  5.     {
  6.         cout << *i << ' ';
  7.         cout << "\n";
  8.     }
  9. }
  10.  
  11.  


While this works and accomplishes what you want, it is not very readable. Having to dereference a pointer in order to get it's contents is something you should avoid while being a novice IMHO. It causes uneeded congestion and there are simpler ways to accomplish the same thing. One way that is a little more clear is to just reference it directly without an iterator.

Vectors are essentially arrays in memory of whatever type you specified. As such, they can be referenced as if they were arrays, making the below code possible.

Code: C++
  1. for(unsigned i=0; i<data.size(); i++)
  2.      cout << data[i] << "\n";
  3.  

Iterators are good when you have complex classes being pushed onto a stack or into the vector array, but for simple things like this, it is often easier to stick with the simple ways.

Moving along to this function...
Code: C++
  1. string getinput()
  2. {
  3.     string dataline;
  4.    
  5.     string name;
  6.     cout << "Enter Name: ";
  7.     getline(cin, name);
  8.     dataline = "Name: " + name + ", ";
  9.    
  10.     string number;
  11.     cout << "Enter Number: ";
  12.     getline(cin, number);
  13.     dataline = dataline + "Number: " + number + ", ";
  14.    
  15.     string address;
  16.     cout << "Enter Address: ";
  17.     getline(cin, address);
  18.     dataline = dataline + "Address: " + address + " ";
  19.    
  20.     return dataline;
  21. }

Since you are using different variables to store the information, you don't need the many appends. You could instead clean it up into one line similar to below.
Code: C++
  1.     string dataline;
  2.    
  3.     string name;
  4.     cout << "Enter Name: ";
  5.     getline(cin, name);
  6.    
  7.     string number;
  8.     cout << "Enter Number: ";
  9.     getline(cin, number);
  10.    
  11.     string address;
  12.     cout << "Enter Address: ";
  13.     getline(cin, address);
  14.     dataline = "Name: " + name + ", "+ "Number: " + number + ", "+ "Address: " + address + " ";
  15.  

As far as the global namespace goes, as long as it is only used inside the source file, I don't really see an issue with it. I never understood the arguments against it. You only run into issues when placing them in headers or when you find the 2 most unlikely conflicts in defines or naming conventions with non-standard libraries. It is such a rarity that I don't agree they are bad. I do, however, think they should be left outside of headers since you may not always want a scope to be active in all things including it.

As far as a support section goes, I actually thought I had one up. Maybe I haven't shown it to all users yet. I'll check it out.

5
Tutorials / C++ Basic RLE Compression
« on: January 11, 2015, 07:48:31 PM »
Code: C++
  1. #include <iostream>// std::cout
  2. #include <fstream> // std::fstream
  3. #include <sstream> // std::ostringstream
  4. #include <random>
  5. /*
  6.         Run Length Encoding - RLE Example to Compression
  7.         Http://Www.CelestialCoding.com
  8.  
  9.         You can go lower level then this tutorial. I will
  10.         only be looking at each byte and checking for duplicates.
  11.         You can do something similar at the macro
  12.         level (look for repeating collections of binary datasets) or even at the lowest
  13.         binary level (look for repeating binary datasets)
  14. */
  15.  
  16. // Used to generate a ~50 meg file for compression
  17. void GenerateRandomFile(){
  18.        
  19.         std::fstream fout;
  20.         fout.open("myfile.txt", std::ios::out);
  21.         for (int i = 0; i < 50000000; i++){
  22.                 int out = rand() % 2;
  23.                 fout << char(out+65);
  24.         }
  25.         fout.close();
  26. }
  27.  
  28. int main(){
  29.         GenerateRandomFile();
  30.  
  31.         // Create a file handlers.
  32.         std::fstream uncompressedFile;
  33.         std::fstream compressedFile;
  34.  
  35.         // Open the file to compress, check for errors
  36.         // Not we are opening in binary mode
  37.         uncompressedFile.open("myfile.txt", std::ios::ios_base::in|std::ios::ios_base::binary);
  38.         if (!uncompressedFile.is_open()){
  39.                 std::cout << "Unable to open file.\n";
  40.                 return -1;
  41.         }
  42.  
  43.         // Store the entire file contents for later iteration
  44.         std::ostringstream fileBuff;
  45.         fileBuff << uncompressedFile.rdbuf();
  46.         std::string     sContents = fileBuff.str();
  47.  
  48.         // Close the handle to the uncompressed file.
  49.         uncompressedFile.close();
  50.  
  51.  
  52.         // Start of the compression algorithm
  53.         // First, create a handle to a new file to write the compressed contents to
  54.         compressedFile.open("newFile.txt", std::ios::out | std::ios::binary);
  55.         if (!compressedFile.is_open()){
  56.                 std::cout << "Unable to create file.\n";
  57.                 return -2;
  58.         }
  59.  
  60.         // Iterate through stored data and look for repititions
  61.         // Start looping through the data to get the first data to check for
  62.         unsigned                uBuffSize = sContents.size()-1;
  63.         unsigned char   ucCurrentByte;
  64.         unsigned char   ucCompareByte;
  65.         unsigned                uCurrentPosition = 0;
  66.  
  67.         while (uCurrentPosition < uBuffSize){
  68.                 // Select the byte to look for repeats
  69.                 ucCompareByte = sContents.at(uCurrentPosition);
  70.                
  71.                 // Keep track of how many times the character repeats.
  72.                 // Never go above 9 repeats
  73.                 unsigned                uRepeats = 0;
  74.  
  75.                 // Find all repeats
  76.                 while (true){
  77.                         // Increment the position by 1
  78.                         uCurrentPosition++;
  79.  
  80.                         // Make sure we don't go over the buffersize
  81.                         if (uCurrentPosition > uBuffSize)
  82.                                 break;
  83.  
  84.                         // Grab the next byte
  85.                         ucCurrentByte = sContents.at(uCurrentPosition);
  86.                        
  87.                         // Check if it repeated
  88.                         if (ucCurrentByte == ucCompareByte){
  89.                                 uRepeats++;
  90.                                 if (uRepeats >= 9)
  91.                                         break;
  92.                         } else {
  93.                                 // If it does not, then we need to break out of this
  94.                                 // check, write what we found, then continue on to the
  95.                                 // next character
  96.                                 break;
  97.                         }
  98.                 }
  99.  
  100.                 // Prepare the data for writting
  101.                 std::ostringstream strOut;
  102.                 if (uRepeats)
  103.                         // If there were more than 2 repeats write the number of instances
  104.                         // and the byte that was repeated
  105.                         if(uRepeats > 2) strOut << uRepeats << ucCompareByte;
  106.                         // Otherwise, just write out the 1-2 repeats
  107.                         else for (int a = 0; a < uRepeats; a++) strOut << ucCompareByte;
  108.                 else
  109.                         // If there were no repeats, just print the character that was affected
  110.                         strOut << ucCompareByte;
  111.  
  112.                 // Write the reults to file for this comparison
  113.                 compressedFile << strOut.str();
  114.         }
  115.  
  116.         // Close the file we were writting to.
  117.         compressedFile.close();
  118.  
  119.         std::cout << "Compressed!\n";
  120.         return 0;
  121. }

Reading and decompressing the file is not show in this, but it is a simple matter of looking for identifiers (numbers 3-9 in this case) and then just repeating that data in memory to decompress the file.

6
Misc / Re: CelestialCoding Redesign
« on: January 11, 2015, 11:20:22 AM »
Lets do it. I'll remove all spam accounts if you can migrate us over to DreamPortal. It looks pretty nice. I'm not quite sure how to unload SimplePortal and all it's modules properly.


EDIT: I've removed all accounts I considered to be suspect. I used 2 criteria.
0-3 posts
200 or more days since last logon.

Many members accounts no longer exist, but they were most likely spam accounts. Since we now have a better bot detector, this major cleanup shouldn't happen again.

Hopefully :P

7
Misc / CelestialCoding Redesign
« on: January 08, 2015, 10:47:38 PM »
It is going on 7 years this year that CelestialCoding has been hosted by Nathan. Over those 7 years, we have compiled and created many tutorials for anybody who happened to stumble onto this site and had a desire to learn. During the 7 years though, issues have begun to crop up and I thought it was time to nip them before it became cancerous.

Before I get into why this is happening, please understand this does not in any way affect the nature of this website. This site always has and, as long as it is within my power, always will be a free opensource tutorial site dedicated to helping the everyday guest learn programming or similar practices.

I mentioned before that some issues were starting to crop up. Most of these issues revolved around tutorials being either deprecated, inaccurate, superfluous, useless, incomplete, or otherwise aimless. The website's shoes were also starting to become a little too big to be filled by itself. Many categories were empty, or have only a single tutorial in it while others were the main area of interest. This redesigned is aimed to fix those issues.

I do hope that active users will respond to this post and lend me their input or ideas on how to categorize the website. I would love to hear some ideas but for now, here is the idea.

1. Focus the site around Tutorials with 1 tutorial area that has what can be called "high quality" or "complete tutorials".
2. No more categories for different languages, they can all be grouped together since only 2 languages were actually common in the 7 years of the websites activity. All languages and tutorials are still accepted, but there will be no more segregation of the languages.
3. A trial area for common tutorials that are good, but involve incomplete series, or is somehow inaccurate or causes some sort of issues will be created as well. This will be a "trial" area for tutorials until they get moved to the other zone.

Those 3 points are what the site is now based around. I intend to revamp the main page as well after I am settled with the current design.

8
Project Advertisment / Re: Axios RPG
« on: December 15, 2014, 07:27:28 AM »
Looks similar to Tibia's ico 2d view. Do you intend to use scrolling for the landscape in similar fashion to mario or just flip the page like old school Pokemon does? It looks pretty nice, I've been distracted playing Dungeon Defenders 2. About time I get back to work on my project as well.

9
Project Advertisment / Re: Game Engine Sneak Peek
« on: November 05, 2014, 12:47:02 AM »
Just adding a small update.... Well, not so small internally, but it is small when it comes to notability for user side stuff. You can modify the resolution yourself now by modifying the userSettings.xml file in the userData folder. I've also upgrade the logger to catch WAY more errors then last time. IT is all in 1 file now too instead of a large number of files. Currently supported resolution:
1920x1080
1600x900
1280x1024
1024x768
800x600

Any custom resolutions you try out that are not pre supported will give odd effects. To change to fullscreen, modify the Windowed option to 0. Have fun!

10
Project Advertisment / Re: Game Engine Sneak Peek
« on: October 13, 2014, 12:49:02 AM »
Won't run for me.

I run the EXE, hear a ding and the program terminates.

Specs:
http://gyazo.com/b23ce7c3ff2d52c0133a30c908b3deab

I didn't have a lot of time to debug it, however the problem seems to be somewhere around here:
http://gyazo.com/988eab96d29988d734c39b18579d7de1

That terminates with: "status = FFFFFFFF (-1.)"

Edit:
http://gyazo.com/fc65710b101807dfbb34f0e2ff24ebe0

The -1 means there was a issue with your screen resolution. I sent you a correct exe to fix it. If anyone else has a similar issue, I'll upload the windowed version for you. Just let me know.

11
Project Advertisment / Game Engine Sneak Peek
« on: October 11, 2014, 12:23:41 PM »
EDIT: I've updated the sneak peak to include new features such as a very basic GUI/HUD/Settings system. Most of the modifications are behind the scenes,so you will not see much change from the previous demo aside from some HUD elements and some new GUI menus. A few points of interest you may want to look at...
1. Look through the template/layout files inside the GUI subfolder in resources.
2. Look through the settings file located in userData folder.

By customizing these files, you can pretty much create your own GUI. I've made it pretty simple to understand in my opinion. All GUI elements get resized dynamically during load time to fit the resolution. This will preserve the location, width, and height of the element while it is on screen. It also preserves the collision box for each GUI element with the same scaling.

Tell me what you think, ideas and critics are welcomed.

DOWNLOAD: Bottom of the post...

***********************************************
So I've been promising Shishka I'd post something to show the progress. I've attached a sample build of the program that may or may not work... There is a lighting issue I've not yet tracked down where the bug is located at. If you run the application, see the intro, and the entire scene looks black, then just alt+f4 out of the application and attempt to run it again. It is set to run in fullscreen mode by default. There is no windowed mode quite yet.

Control:
'~' - Brings up command console + shows mouse
'Ctrl' -Crouch
'Space' - Jump
'WASD' - Move around

Commands for command console:
'toggle_fps' - turns on fps
'program_quit' - Exits application

Tell me what you think, there is a level file as well you can checkout and try modifying to adjust the level. test2 is the currently loaded model since it's the largest map I've made so far.

12
C++ / Re: Re: Challenge: Celestialkey's Submission
« on: April 13, 2014, 11:14:59 AM »
This should never be within a header file ever:
Code: [Select]
using namespace std;
I suspected this was what you were doing when I didn't see any namespace specifier explicitly within the cpp source and any using directives... The reason is because now if somebody goes to use your header, certain unintentional identifier ambiguities may exist, even if his/her code was careful to avoid them. Irregardless, writing that anywhere in your code essentially defeats the whole point of namespaces.

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c
http://www.cplusplus.com/forum/beginner/25538/
Artifacts from testing. Also, I don't believe any sensible person would create functions that conflict with the std namespace. I'll fix this one since it makes sense and I agree with it.

Another thing, with C++ you hardly should ever be required to use global variables:

Code: [Select]
CFileSystem f;

char* file;
[/code]
It was a quick and dirty demonstration of the class' use. No need for setting anything more complicated up. There is nothing wrong with using globals anyhow with small programs. It only comes into play when you use larger applications and your code starts looking like spaghetti code. In term of 'good' and 'bad', programming is still suffering from all the pitfalls it has had in the past and there is plenty of programming that goes on everyday with professions that I, and many others, consider bad practice regardless of if they use globals. I feel like this one was nitpicking.

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.
I only use the derint header to traverse directories. This action is a LOT easier in Linux then it is in windows. Windows has no true functions to traverse directories, it only has very basic and clunky methods which would cause the code to become close to unreadable. ALL file input and output is done using the native OS, only directory traversal is using the derint header. If you were to use boost, it would take the majority the functions over since boost gives you plenty of alternatives for traversing, reading, and writing to files.

All in all, the main thing to remember here is that this is a response to a specific challenge. No need for proper etiquette when your writing code for a specific 1 goal purpose.
Thanks for your input otherwise.

13
Challenges / Re: Challenge: Custom Zip File
« on: April 12, 2014, 04:05:03 PM »
EDIT: So.. there is some memory issue with this. I'm not sure where, but I'm working on fixing it... Damnit :(
EDIT2: Fixed it. I forgot to remove some padding I wrote to the file causing the offset to be 10 bytes off giving strange characters. Updated the code. I also added in some new code to grab the file from memory. Check it out. Updated attached file to reflect the new archive file.
EDIT3: Modified the code slightly to fall in line with certain etiquettes.

Here is my entry for this challenge. I based the entire system off of books. Each page in the book is a set of files and each book has a table of contents with offsets pointing to each chapter (specific file on a page). For now, all you can do is create books, read their stored data, and tear them apart. I can improve this and I most likely will later on for use in some of my projects that have a large amount of files.

FEATURES!
- Preserves folder structure and will recreate folder structure when tearing from the book.
- Easy to use
- Mostly error proof* All major points are checked for errors, but once things get rolling, the program assumes you won't have a power outage or something similar
- File structure is explained indepth in the header
- Very well commented

LIMITATIONS!
The limits of this program are basically described by the data types it uses.
It can store up to (unsigned short)[65,535] files and directories
It can store up to (unsigned long)[4,294,967,295]
Each page it adds to the book can also be around that size as long as it does not exceed a long's size;
You MUST use '\\' characters instead of forward slashes. Not doing so will cause bad things to happen... Like memory overflows.

A few things to note...
- This relies on the use of the dirent header which can be found here http://softagalleria.net/download/dirent/?C=M;O=D
The header is small and light weight which makes it good for small operations such as this.

- The class is not 100% cross platform. Each OS has different ways to create files/directories. Because of this, I focused on the Windows OS while making this.
Note that I tried to keep the data structures and functions very obvious. It should be easy to port this if anyone wants to do that.

- This was built for Multibyte projects. Attempting to use this in a unicode environment will cause it to fail. If you wanted to convert it over to unicode, you would have to change all the strings to wstrings and exchange a few functions that make heavy use of those strings.

:)

See if you can do better, or improve on my design if you don't know where to start.



[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

OH YEA! If you need a example, I've included the entire project as a archived source in my own format. :)

[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
main.cpp
Code: C++
  1. #include "CFileSystem.h"
  2.  
  3. int main(){
  4.         CFileSystem f;
  5.         char* file;
  6.         std::string s = "C:\\Users\\Celestialkey\\Desktop\\Developer Drive Backup\\Projects\\Active\\Engine\\DXGameCraft\\data";
  7.  
  8.         f.FastenBook(s, "C:\\Users\\Celestialkey\\Documents\\Visual Studio 2012\\Projects\\CelFiSys\\Release\\data.key");
  9.         f.OpenBook("C:\\Users\\Celestialkey\\Documents\\Visual Studio 2012\\Projects\\CelFiSys\\Release\\data.key");   
  10.  
  11.         std::cout << "Details...\n------------------------\n";
  12.         f.ReadTableOfContents();
  13.         f.ReadDirectories();
  14.         f.ReadFiles();
  15.         std::cout << "--------------------------\n";
  16. //      string getFile;
  17. //      cin >> getFile;
  18. //      long sizet = f.GrabFileSize(getFile);
  19. //      cout << "File size of demo.txt " << sizet << endl;
  20. //      if(!sizet){
  21. //              f.CloseBook();
  22. //              cout << "Did not find file." << endl;
  23. //              getchar();
  24. //              return 1;
  25. //      }
  26. //      file = new char[sizet];
  27. //
  28. //      f.GrabFile(getFile, file);
  29. //      cout << file << endl;
  30. //     
  31. //      delete [] file;
  32. //      getchar();
  33.         f.TearBook();
  34.         f.CloseBook();
  35.         return true;
  36. }

CFileSystem.h
Code: C++
  1. #pragma once
  2.  
  3. #include <dirent.h>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <fstream>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. struct sPageData{
  12.         char    fileName[50];
  13.         char    filePath[255];
  14.         unsigned long   fileOffset;
  15.         unsigned long   fileSize;
  16. };
  17.  
  18. struct sTableOfContents{
  19.         char    bookTitle[255];
  20.         unsigned short  numOfChapters;
  21.         unsigned short  numOfPages;
  22.         std::string     rootDir;
  23.         std::string*    directories;
  24. };
  25.  
  26.  
  27.  
  28. class CFileSystem{
  29. private:
  30.         // All private variables are used to open and read in
  31.         // books created earlier. All create variables are
  32.         // created and destroyed during the create process.
  33.         sTableOfContents*       _readBookContents;
  34.         std::vector<std::string>                _chapterList;
  35.         std::vector<sPageData>  _pageList;
  36.         std::ifstream                   _inBook;
  37.  
  38. private:
  39.         int             _analyzeDir(std::string, std::vector<std::string>&, std::vector<std::string>&);
  40.         int             _buildTableOfContents(std::vector<std::string>&, std::vector<std::string>&, sPageData*, sTableOfContents&, std::string&);
  41.         long    _calculateOffset(long, sPageData*);
  42.         int             _writeToManuscript(sTableOfContents&, std::vector<std::string>&, sPageData*, std::ofstream&);
  43.         bool    _findFile(std::string s, sPageData& );
  44. public:
  45.         // Initializers/Deconstructors
  46.         CFileSystem();
  47.         ~CFileSystem();
  48.  
  49.         // Initializing Functions
  50.         bool OpenBook(std::string bookname);
  51.         void CloseBook();
  52.  
  53.         // Appending Functions
  54.         // None yet
  55.  
  56.         // Creation Functions
  57.         bool FastenBook(std::string dir, std::string outBook);
  58.         bool TearBook(std::string inBook);
  59.         bool TearBook();
  60.  
  61.         // Output Functions
  62.         void ReadFiles();
  63.         void ReadDirectories();
  64.         void ReadTableOfContents(bool = false);
  65.  
  66.         // Grab Functions
  67.         bool GrabFile(std::string filename, void* out);
  68.         char* GrabFile(std::string filename);
  69.  
  70.         unsigned long GrabFileSize(std::string filename);
  71.        
  72. };
  73.  
  74. //////////////////////////////////////////////////////////////////////////////////
  75. // Book ]
  76. //              -> Leaf ]
  77. //                              -> Page
  78. //////////////////////////////////////////////////////////////////////////////////
  79. //                                                              Book Structure                                                                  //
  80. //////////////////////////////////////////////////////////////////////////////////
  81. /*
  82. //      RootDir         [BYTE][255]
  83. //      DirCount        [SHORT][1]
  84. //
  85. //      DirPath         [BYTE][255]
  86. //      ...
  87. //      DirPath         [BYTE][255]
  88. //////////////////////////////////////////////////////////////////////////////////
  89. //      FileCount       [SHORT][1]
  90. //////////////////////////////////////////////////////////////////////////////////
  91. //      FilePath        [BYTE][255]
  92. //      FileName        [BYTE][50]
  93. //      FileSize        [LONG][1]
  94. //      FileOffset      [LONG][1]
  95. //      ...
  96. //      FilePath        [BYTE][255]
  97. //      FileName        [BYTE][50]
  98. //      FileSize        [LONG][1]
  99. //      FileOffset      [LONG][1]
  100. //////////////////////////////////////////////////////////////////////////////////
  101. //      FileData        [BYTE][sizeof(fileData)]
  102. //      ...
  103. //      FileData        [BYTE][sizeof(fileData)]
  104. */
  105. //////////////////////////////////////////////////////////////////////////////////
  106. //                                                                      Explained                                                                       //
  107. //////////////////////////////////////////////////////////////////////////////////
  108. /*
  109.  Fastening Steps
  110.         1. Iterate through directory provided and create manuscript
  111.         2. Use manuscript to write the table of contents
  112.         3. Write the table of contents to the book with padding to ensure set header size
  113.         4. Write raw binary data for each file into book
  114.  
  115.  
  116. */

CFileSystem.cpp
Code: C++
  1. #include "CFileSystem.h"
  2. using namespace std;
  3.  
  4. CFileSystem::CFileSystem(){
  5.         _readBookContents = 0;
  6. }
  7. CFileSystem::~CFileSystem(){
  8.         if(_readBookContents)
  9.                 CloseBook();
  10. }
  11. int CFileSystem::_analyzeDir(string dir, vector<string>& sChapters, vector<string>&sPages) {
  12.         DIR *getDir;
  13.         getDir = opendir(dir.c_str());
  14.  
  15.         if(getDir == nullptr) {
  16.                 cerr << endl << "Error opening directory " << dir
  17.                          << " (errno: " << errno << ")" << endl;
  18.                 return errno;
  19.         }
  20.         struct dirent *directoryPointer;
  21.         struct stat filestat;
  22.         string path;
  23.         while( (directoryPointer = readdir(getDir)) ) {
  24.                 //Skip current object if it is this directory or parent directory
  25.                 if(!strncmp(directoryPointer->d_name, ".", 1) || !strncmp(directoryPointer->d_name, "..", 2))continue;
  26.                 if(dir==".") path = directoryPointer->d_name;
  27.                 else             path = dir + "\\" + directoryPointer->d_name;
  28.  
  29.                 // Check for invalid pointers
  30.                 if(stat(path.c_str(), &filestat)) continue;
  31.  
  32.                 // Add to either list
  33.                 if(S_ISDIR(filestat.st_mode)) {
  34.                         sChapters.push_back(path);
  35.                         _analyzeDir(path,sChapters,sPages);
  36.                         continue;
  37.                 }else{
  38.                         sPages.push_back(path);
  39.                 }
  40.         }
  41.         closedir(getDir);
  42.        
  43.         return 0;
  44. }
  45. int CFileSystem::_buildTableOfContents(vector<string>& sChapters, vector<string>&sPages, sPageData* fileList, sTableOfContents& table, string& dir){
  46.         int dirOffset = dir.size()-(dir.size()-dir.find_last_of("\\"));
  47.  
  48.         // Get file statistics
  49.         for(unsigned int i=0; i<sPages.size(); i++){
  50.                 // Size
  51.                 struct stat pageDetails;
  52.                 stat(sPages[i].c_str(), &pageDetails);
  53.                 fileList[i].fileSize = pageDetails.st_size;
  54.  
  55.                 // Find name
  56.                 // Locate the last '\', add 1 to the position, and save everything after that position to a string
  57.                 string name = sPages[i].substr(sPages[i].find_last_of('\\')+1, sPages[i].size());
  58.                 strcpy_s(fileList[i].fileName, 50, name.c_str());
  59.                
  60.                 // Path
  61.                 // Locate the last '\', save everything from position 0 to found '\'
  62.                 string path = sPages[i].substr(0, sPages[i].find_last_of('\\'));
  63.                 path = path.substr(dirOffset, path.size());
  64.                 path.insert(0, ".");
  65.                 strcpy_s(fileList[i].filePath, 255, path.c_str());
  66.         }
  67.         // Fill out rest of info for ToC
  68.         table.directories = new string[sChapters.size()];
  69.         for(unsigned int i=0; i<sChapters.size(); i++){
  70.                 sChapters[i] = sChapters[i].substr(dirOffset, sChapters[i].size());
  71.                 sChapters[i] = sChapters[i].insert(0, ".");
  72.                 table.directories[i] =sChapters[i];
  73.         }
  74.  
  75.         table.numOfChapters = sChapters.size();
  76.         table.numOfPages = sPages.size();
  77.  
  78.         return 0;
  79. }
  80. int CFileSystem::_writeToManuscript(sTableOfContents& table, vector<string>&sPages, sPageData* files, ofstream& out){
  81.         // Keep track of current offset
  82.         long curOffset = 0;
  83.         int structSize = 0;
  84.         long fileOffset = 0;
  85.  
  86.         // Get the size of each file header
  87.         // This can be found by looking at the logic structure
  88. //--------------------------------------
  89. //      FilePath        [BYTE][255]
  90. //      FileName        [BYTE][50]
  91. //      FileSize        [LONG][1]
  92. //      FileOffset      [LONG][1]
  93. //--------------------------------------
  94.         structSize =
  95.                 (sizeof(char)*255)
  96.                 +(sizeof(char)*50)
  97.                 +sizeof(unsigned long)
  98.                 +sizeof(unsigned long);
  99.         cout << "File header size: " << structSize << "\n";
  100.  
  101.         // For reference for the order, look back to the header
  102.         // First we write single data
  103.         // Buffer
  104.         char outc[255] = {'\0'};
  105.         out.write(reinterpret_cast <const char*> (&table.rootDir), sizeof(char)*255);
  106.         curOffset+= sizeof(char)*255;
  107.  
  108.         out.write(reinterpret_cast <const char*> (&table.numOfChapters), sizeof(unsigned short));
  109.         curOffset+= sizeof(unsigned short);
  110.  
  111.         for(unsigned short i=0; i < table.numOfChapters; i++){
  112.                 strcpy_s(outc, 255, table.directories[i].c_str());
  113.                 out.write((char*)outc, sizeof(char)*255);
  114.                 curOffset+= (sizeof(char)*255);
  115.                 memset(outc, 0, 255);
  116.  
  117.         }
  118.         out.write(reinterpret_cast <const char*> (&table.numOfPages), sizeof(unsigned short));
  119.         curOffset+= sizeof(unsigned short);
  120.  
  121.         // Calculate the offset for the first file
  122.         fileOffset =
  123.                 (sPages.size()*structSize)      // Number of headers that will be in the file * how large they are
  124.                 + curOffset;                                    // The current offset that the descriptor header took up
  125.  
  126.         // Write each file header to the book
  127.         for(unsigned int i=0; i<sPages.size(); i++){
  128.                 // Parse together the file name
  129.                 string file = files[i].filePath + string("\\") + files[i].fileName;
  130.  
  131.                 // Write the file path
  132.                 strcpy_s(outc, 255, files[i].filePath);
  133.                 out.write((char*)outc, sizeof(char)*255);
  134.                 memset(outc, 0, 255);
  135.  
  136.                 // Write the file name
  137.                 strcpy_s(outc, 255, files[i].fileName);
  138.                 out.write((char*)outc, sizeof(char)*50);
  139.                 memset(outc, 0, 255);
  140.  
  141.                 // Write file size
  142.                 out.write(reinterpret_cast <const char*> (&files[i].fileSize), sizeof(unsigned long));
  143.  
  144.                 // Write the future file offset
  145.                 out.write(reinterpret_cast <const char*> (&fileOffset), sizeof(unsigned long));
  146.  
  147.                 // Prepare next future file offset
  148.                 fileOffset += files[i].fileSize;
  149.         }
  150.  
  151.         // Write each file object to the book
  152.         for(unsigned int i=0; i<sPages.size(); i++){
  153.                 ifstream inFile;
  154.                 inFile.open(sPages[i].c_str(), ios::binary);
  155.                 if(inFile.is_open()){
  156.                         char* data = new char[files[i].fileSize];
  157.                         inFile.read(data, files[i].fileSize);
  158.                         out.write(data, files[i].fileSize);
  159.                         delete [] data;
  160.                         inFile.close();
  161.                 } else {
  162.                         cout << "Error opening file " << sPages[i] << endl
  163.                                 << "File may not exist or it may be in use by another program" << endl
  164.                                 << "User running the file may also not have permissions to it." << endl
  165.                                 << "Aborting book creation\n";
  166.                         return -1;
  167.                 }
  168.         }
  169.         return 0;
  170. }
  171. bool CFileSystem::_findFile(string s, sPageData& p){
  172.         // Attempt to find via full path
  173.         for(short i=0; i<_readBookContents->numOfPages; i++){
  174.                 // string::compare returns 0 when they are equal
  175.                 if(!s.compare(string(_pageList[i].filePath + string("\\") +_pageList[i].fileName))){
  176.                         p= _pageList[i];
  177.                         return true;
  178.                 }
  179.         }
  180.         // Attempt to find ANY file that has that name
  181.         for(short i=0; i<_readBookContents->numOfPages; i++){
  182.                 // string::compare returns 0 when they are equal
  183.                 if(!s.compare(_pageList[i].fileName)){
  184.                         p= _pageList[i];
  185.                         return true;
  186.                 }
  187.         }
  188.         return false;
  189. }
  190. void CFileSystem::ReadDirectories(){
  191.         cout << "ROOT: " << _readBookContents->rootDir<< endl;
  192.         for(unsigned int i=0; i<_chapterList.size(); i++)
  193.                 cout <<"SUB : "<< _chapterList[i].c_str() << endl;
  194. }
  195. void CFileSystem::ReadFiles(){
  196.         for(unsigned int i=0; i<_pageList.size(); i++){
  197.                 cout << _pageList[i].fileName << endl;
  198.         }
  199. }
  200. void CFileSystem::ReadTableOfContents(bool details){
  201.         if(!_readBookContents) return;
  202.         cout << "Root [" << _readBookContents->rootDir << "]\n"
  203.                  << "Number of Directories: " << _readBookContents->numOfChapters << endl
  204.                  << "Number of Files: " << _readBookContents->numOfPages << endl;
  205.         if(details){
  206.                 for(unsigned short i=0; i<_readBookContents->numOfPages; i++){
  207.                         cout << "File\n---------------------\n"
  208.                                 << "Name: " << _pageList[i].fileName << endl
  209.                                 << "Path: " << _pageList[i].filePath << endl
  210.                                 << "Size: " << _pageList[i].fileSize << "(bytes)" << endl
  211.                                 << "Offset: " << _pageList[i].fileOffset << endl << endl;
  212.                 }
  213.         }
  214. }
  215. bool CFileSystem::FastenBook(string dir, string outBook){
  216.         // Define what is required
  217.         vector<string> sChapters;
  218.         vector<string> sPages;
  219.         sPageData*                      files;  // Contains all file header data
  220.         sTableOfContents        dirs;   // Contains reference data
  221.  
  222.         dirs.rootDir = dir.substr(dir.find_last_of("\\"), dir.size());
  223.         dirs.rootDir = dirs.rootDir.insert(0, ".");
  224.  
  225.         // Build a file list.
  226.         _analyzeDir(dir, sChapters, sPages);
  227.  
  228.         // Create file entries
  229.         files = new sPageData[sPages.size()];
  230.  
  231.         // Fill requires data structures
  232.         _buildTableOfContents(sChapters, sPages, files, dirs, dir);
  233.  
  234.         // Open up the empty book
  235.         ofstream manuscript;
  236.         manuscript.open(outBook, ios::binary);
  237.                
  238.         _writeToManuscript(dirs, sPages, files, manuscript);
  239.  
  240.         manuscript.close();
  241.         delete [] files;
  242.         delete [] dirs.directories;
  243.         return true;
  244. }
  245. bool CFileSystem::OpenBook(string book){
  246.         // Check for an already opened book
  247.         if(_inBook.is_open()) return false;
  248.  
  249.         // Open the book
  250.         _inBook.open(book.c_str(), ios::binary);
  251.         if(!_inBook.is_open()) return false;
  252.         // Since the file exists, create the ToC
  253.         _readBookContents = new sTableOfContents;
  254.  
  255.         // Remember the file structure
  256. //      RootDir         [BYTE][255]
  257. //      DirCount        [SHORT][1]
  258. //      dirPath         [BYTE][255]
  259.         char buf[255] = {'\0'};
  260.         // Read in the root directory
  261.         _inBook.read(buf, sizeof(char)*255);
  262.         _readBookContents->rootDir=buf;
  263.  
  264.         // Read in the number of directories stored
  265.         _inBook.read(reinterpret_cast <char*> (&_readBookContents->numOfChapters), sizeof(unsigned short));
  266.  
  267.         // Allocate enough space for each directory path
  268.         _readBookContents->directories = new string[_readBookContents->numOfChapters];
  269.         for(unsigned short i=0; i< _readBookContents->numOfChapters; i++){
  270.                 _inBook.read(buf, sizeof(char)*255);
  271.                 _readBookContents->directories[i] = buf;
  272.                 _chapterList.push_back(buf);
  273.                 memset(buf, 0, 255);
  274.         }
  275.  
  276.         // Convert the relative paths into absolute paths
  277.         GetCurrentDirectory(255, buf);
  278.         cout << "Current Directory: " << buf << endl;
  279.         for(unsigned short i=0; i< _readBookContents->numOfChapters; i++){
  280.                 _chapterList[i] = _chapterList[i].substr(1, _chapterList[i].size());
  281.                 _chapterList[i] = _chapterList[i].insert(0, buf);
  282.                 _readBookContents->directories[i] = _chapterList[i];
  283.         }
  284.  
  285. //////////////////////////////////////////////////////////////////////////////////
  286. //      FileCount       [SHORT][1]
  287. //////////////////////////////////////////////////////////////////////////////////
  288. //      FilePath        [BYTE][255]
  289. //      FileName        [BYTE][50]
  290. //      FileSize        [LONG][1]
  291. //      FileOffset      [LONG][1]
  292. //////////////////////////////////////////////////////////////////////////////////
  293.         // Load in the next part describing the number of files
  294.         _inBook.read(reinterpret_cast <char*> (&_readBookContents->numOfPages), sizeof(unsigned short));
  295.         sPageData tmp;
  296.         for(unsigned short i=0; i<_readBookContents->numOfPages; i++){
  297.                 _inBook.read(reinterpret_cast <char*> (&tmp.filePath), sizeof(char)*255);
  298.                 _inBook.read(reinterpret_cast <char*> (&tmp.fileName), sizeof(char)*50);
  299.                 _inBook.read(reinterpret_cast <char*> (&tmp.fileSize), sizeof(unsigned long));
  300.                 _inBook.read(reinterpret_cast <char*> (&tmp.fileOffset), sizeof(unsigned long));
  301.                 _pageList.push_back(tmp);
  302.                 memset(&tmp, 0, sizeof sPageData);
  303.         }
  304.  
  305.         // The file is now "loaded" into memory.
  306.         // Since files can be very large in terms of size, it is
  307.         // best to only load in the memory pointers until
  308.         // the user requests a file in particular.
  309.         return true;
  310. }
  311. bool CFileSystem::TearBook(string b){
  312.         if(!_inBook.is_open())
  313.                 OpenBook(b);
  314.         TearBook();
  315.         CloseBook();
  316.         return true;
  317. }
  318. bool CFileSystem::TearBook(){
  319.         if(!_inBook.is_open()) return false;
  320.  
  321.         // First create the directory root
  322.         CreateDirectory(_readBookContents->rootDir.c_str(), NULL);
  323.         // Then create the directory structure
  324.         for(short i=0; i<_readBookContents->numOfChapters; i++){
  325.                 CreateDirectory(_readBookContents->directories[i].c_str(), NULL);
  326.         }
  327.  
  328.         // Tear each page from the book
  329.         for(short i=0; i<_readBookContents->numOfPages; i++){
  330.                 // Navigate to each offset and read it into a buffer
  331.                 char* buff = new char[_pageList[i].fileSize];
  332.                 _inBook.seekg(_pageList[i].fileOffset);
  333.                 _inBook.read(buff, _pageList[i].fileSize);
  334.  
  335.                 // Create the entire file path [ path + name ]
  336.                 string fp = _pageList[i].filePath + string("\\") + _pageList[i].fileName;
  337.                 ofstream outFile;
  338.                 outFile.open(fp.c_str(), ios::binary);
  339.                
  340.                 // This file may be corrupt in some way, attempt to restore
  341.                 // the rest of the files anyhow
  342.                 if(!outFile.is_open()){
  343.                         delete [] buff;
  344.                         continue;
  345.                 }
  346.  
  347.                 // Write the data to restore the file
  348.                 outFile.write(buff, _pageList[i].fileSize);
  349.                 outFile.close();
  350.                 delete [] buff;
  351.         }
  352.         return true;
  353. }
  354. void CFileSystem::CloseBook(){
  355.         if(_inBook.is_open()){
  356.                 _inBook.close();
  357.         }
  358.         if(_readBookContents){
  359.                 if(_readBookContents->directories){
  360.                         delete [] _readBookContents->directories;
  361.                 }
  362.                 delete _readBookContents;
  363.                 _readBookContents = 0;
  364.         }
  365. }
  366. bool CFileSystem::GrabFile(string f, void* out){
  367.         // Cast data into type
  368.         char* p = static_cast<char*>(out);
  369.         // Locate and load file into buffer from file
  370.         sPageData s;
  371.         if(!_findFile(f, s)) return false;
  372.         _inBook.seekg(s.fileOffset, ios::beg);
  373.         _inBook.read(p, s.fileSize);
  374.  
  375.         return true;
  376. }
  377. unsigned long CFileSystem::GrabFileSize(string f){
  378.         sPageData s;
  379.         if(!_findFile(f, s)) return 0;
  380.         return s.fileSize;
  381. }

14
Challenges / Challenge: Custom Zip File
« on: April 11, 2014, 05:04:04 PM »
Challenge: Create a simple class that works similarly to WinZip or Rar. No compression is needed for this challenge. The goal is to implement your own version of grouping multiple files into 1 file while still preserving the data.

Any extras you add in are up to you. There requirements to full fill are below.

:REQUIREMENTS:
1. Must be able to combine at least 6 files into one
2. Must be able to preserve folder structures
3. Must be able to extract files
4. Must be able to preserve files of different types


Lets do it!

15
Challenges / Re: C/C++ Challenge: String Bits
« on: April 11, 2014, 04:59:57 PM »
The apple fell from the tree.
00000000000000001100000011011110


"rotre."

Now?

I understand now.

16
Challenges / Re: C/C++ Challenge: String Bits
« on: April 09, 2014, 06:47:45 PM »
Summary: Grab characters from a string based on the set bits of a certain datatype. Ex:
Code: [Select]
(unsigned 32 bit) 0xC0DE = 49374
00000000 00000000 11000000 11011110

At the 17th index of the binary representation of the number 0xC0DE (49374), we see our first 1. Cyclically iterate the bits within the given bit mask and grab characters based on all of the set bits.

The result of the described algorithm and the number above, on the string "The apple fell from the tree." would be:
Code: [Select]
The apple fell f(r)(o)m the (t)(r)e(e)(.)
The characters retrieved are: "rotre."

I don't understand...

17
Project Advertisment / Re: New Age OpenGL Engine/Game
« on: April 07, 2014, 11:43:10 PM »
Just another update on my terrain/weather system. See the image below.

It demonstrates a few techniques currently being implemented in the scene. The techniques can be seen below. When examining the image, understand that the terrain map is HUGE. The camera is 12 units up which is equal to about 120 ft in the game world.

1. Level of detail - Notice area circled with arrow. The detail map only renders detail to a certain distance away.
2. Day/Night system - The image was taken during morning hours.
3. Multi texturing - Texturing system is based off height of terrain and the main texture that is laid over the entire map and then enhanced using LOD.
4. Spanning clouds - Clouds contain multiple textures blended together moving at different rates. I'm debating using a perturbed image to change the cloud forms, but for now, I don't really care enough about sky detail.

Next up, tessellation for higher map detail nearby and some actual environmental objects such as trees.
1414-0

18
Beta Releases / Re: C++'s Random Song.
« on: April 07, 2014, 11:19:10 PM »
You're right. I'm only seeing two MOVs per call. What an enigma...

19
C# / Re: Converting C++ to C#
« on: April 07, 2014, 07:34:19 AM »
"Even if it is implicit, they are still declared as either private, public or protected. Just because you don't specify one, doesn't mean it's not, by default, set to private." - This is what I said though:
Misunderstood, apologies.

C++ is all about OOP too, but the C++ code given from the start doesn't demonstrate that very well. :)

Yea... can't really argue that...

20
Code Snipplets / Re: Piglatin Converter
« on: April 07, 2014, 07:19:43 AM »
Locked due to flaming.

Sigh. Mr. Key, can you please just delete all of our posts up to the point at which this began? I would appreciate it.

I cannot delete all of the posts since he has valid points I believe are constructive and important for a general programmers to know and understand. I can and will however remove some of the more emotional posts that contain no real value.

Understand that I will not being doing this again. Next time, I will lock the post as is and issue a warning.

Because they are being removed though, this topic is being locked.

21
Code Snipplets / Re: Piglatin Converter
« on: April 06, 2014, 10:31:49 PM »
1: No, I wasn't a Pascal programmer. My naming conventions are efficient for me.
2: I know what Strings are. This should easily show it: "if (Word_LowerCase[0] != 'y')"
3: http://msdn.microsoft.com/en-us/library/11w09h50%28v=vs.110%29.aspx
4: I think System.Console.Out.WriteLine is better, as I know exactly where WriteLine is coming from.
5: I don't use LINQ because I haven't learned LINQ, yet. Also, I don't program in C# often, so I didn't know about Select either.



I agree with you 100% here. I thought your post was tailored quite well to the question asked.

22
Beta Releases / Re: C++'s Random Song.
« on: April 06, 2014, 10:26:36 PM »
The Beep() function from the Windows header only has 2 parameters, there is no 3rd for volume: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679277%28v=vs.85%29.aspx
I thought the same thing. But as said earlier... It works. Assuming that is the real source code, they did get it to compile for them and it does work correctly when you run the exe. Maybe a modified header or something similar?

23
C# / Re: [6] Switch Statements
« on: April 06, 2014, 10:17:39 PM »
As an example...
Code: [Select]
char c = 'A';
bool eq = Char.ToLower(c, CultureInfo.CurrentCulture).Equals('a');

Although for user input, because you're just assuming that the integer can be parsed, you will get an exception thrown if the user enters an invalid string which can't be represented as an integer, thus you *should* be using int.TryParse() instead. :)
You're correct however, I didn't have a need to use it since this tutorial was for switch statements and nothing else. You don't introduce random code snip-lets in tutorials when it is unrelated. Causes confusion.

24
C# / Re: Converting C++ to C#
« on: April 06, 2014, 10:13:38 PM »
In c#, all your functions are located withen a namespace, they also have to be declared as public, private, or protected. After that they are called. Your console.writeline needs to be changed if your trying to display in information to
Code: [Select]
Console.WriteLine("{0}", num); If you are trying to display. Otherwise, can we get a copy of your original C++ code so we can help you more?

No, that's not true. Depending on where they reside, they have a default access modifier. Typically this is 'private', but they do not have to be declared explicitly.

Lots of that C++ code though is junk (there's no need for all of those variables at the top with that much scope). That defeats the whole point of the functions.

I think you're misunderstanding my answer. I never said it had to be declared explicitly. Even if it is implicit, they are still declared as either private, public or protected. Just because you don't specify one, doesn't mean it's not, by default, set to private. Also, this behavior depends on your compiler. Many compilers give options to modify the default compiler settings. Case and point, MSVS 2012 allows you to set class declarations to automatically be set to public or protected if it's not specified. This is of course bad practice since it makes code unreadable by anyone outside the project. I can not for the of me image why anyone would do this, but none the less, it is possible. Also, the question was "I am trying to convert my C++ program to C#". Last time I checked C# is ALL about OOP style programming. This means heavy reliance on namespaces.

25
C# / Re: Square/Cube GUI
« on: April 06, 2014, 10:03:16 PM »
You actually don't need to call ToString() because with the + operator ToString() will be called anyways implicitly, thus ToString() is redundant. The compiler knows that it's being assigned to a string variable (the backing value of the Text property for that Label control).
Although that is true, most compilers these day would optimize it and remove the redundancy during the compilation process. There is nothing wrong with using ToString to make the code more readable IMO.

26
Project Advertisment / Re: New Age OpenGL Engine/Game
« on: April 05, 2014, 01:53:33 AM »
Just posting an update on this. I've gotten a lot of the feature I want up an running now. I'm currently working on getting multi layer texturing in place and LOD put in place so that I can render my quad trees in high detail nearby and low detail far away. A small picture below of my progress currently. It is only showing the terrain loaded, but it is using a quad tree and frustum culling to only render terrain you are looking at. It also has dynamic lighting enabled but it has a strange look because of my normal calculations. Once I get something related to a game up and running, I'll ensure I post some tutorials.

Also, I've decided to work on this in DirectX11 (Most features used are still available in DX9-10). I can convert the project over later to OpenGL since the languages are pretty similar in terms of what they require to render. OpenGL makes it somewhat harder though. :(

Tell me what you think!

27
Code Snipplets / Re: Piglatin Converter
« on: March 26, 2014, 09:14:43 AM »
That's all true, but the goal isn't to make the code smaller, as that has no real application. And though I would prefer C over C#, mager wrote the original program in C#, so I decided that he would have no use for a C version, and it wouldn't help him with coding in C#.
Point taken, didn't notice it was C# looking at the original code. Looks like C to me until I hit the ToLower function.

28
C# / Re: Project
« on: March 26, 2014, 09:13:03 AM »
What if instead of using a server model, it used a p2p model? The host would 'lend' their compiler to other users and the results would be compiled on their machine and sent back? I can't see a server doing this as a good idea since you would run into dependency errors. Not to mention the fact that the program would by default be compiled for that local system architecture. If it is a teaching tool, there would be a teacher hosting the source, or so I'd assume. What do you think?

29
Code Snipplets / Re: Piglatin Converter
« on: March 25, 2014, 11:39:48 PM »
Ok. I went through your code, and realized that it was very repetitive and didn't utilize C# for the one reason it's a decent language: it's massive pre-made libraries.
Here is an optimized version of your code.

Code: C
  1. using System;
  2.  
  3. namespace Piglatin
  4. {
  5.     class Program
  6.     {
  7.         static Char[] Vowels = "aeiouy".ToCharArray();
  8.  
  9.         static String ToPigLatin(String Sentence)
  10.         {
  11.             String Result = "";
  12.             foreach (String Word in Sentence.Split(' '))
  13.             {
  14.                 Result += WordToPigLatin(Word) + " ";
  15.             }
  16.  
  17.             return Result;
  18.         }
  19.  
  20.         static String WordToPigLatin(String Word)
  21.         {
  22.             String Word_LowerCase = Word.ToLower();
  23.             Int32 Index_FirstVowel = Word_LowerCase.IndexOfAny(Vowels);
  24.  
  25.             if (Index_FirstVowel == 0)
  26.             {
  27.                 if (Word_LowerCase[0] != 'y')
  28.                 {
  29.                     return Word + "yay";
  30.                 }
  31.                 return Word.Substring(1) + "yay";
  32.             }
  33.             return Word.Substring(Index_FirstVowel) + Word.Substring(0, Index_FirstVowel) + "ay";
  34.         }
  35.  
  36.         static void Main(String[] args)
  37.         {
  38.             // Notice that words starting with silent constanants don't get processed correctly with this algorithm.
  39.             String Sentence = "happy duck glove egg inbox eight you hour";
  40.  
  41.             System.Console.Out.WriteLine(ToPigLatin(Sentence));
  42.         }
  43.     }
  44. }

There are many better ways to accomplish this. Using actual C++ classes could allow the code to be even smaller than the C# version you posted. Even C has some functions that could have made this easier.

30
C# / Re: Project
« on: March 19, 2014, 01:05:20 PM »
* One that I REALLY WANT is a clone of codepad. I would like collaborative editing but compiling/running would be awesome. It's not a hard idea - but there are few caveats such as restricting internet access (don't want random people to build a malware application to attack or listen on a port - I think a short timeout period for anonymous, longer but still short for registered and longer for paid people), running it in a sandbox such that it can't access any files on the system except in the directory that was created to run it (which would also allow for registered users to upload libraries). Anyone attempting to exploit the system would be automatically banned.

Isn't this the same as the CCTC thing I built a while back. Basically multiplayer notepad, right? I remember the developement went smoothly until for some reason my ISP derped my connection and I couldn't test/debug it anymore.

This would be way different. This isn't just storing a copy of the code like a gist but rather compiling it, running it, and showing the output. These tools are great for showing examples/explaining things - especially if the user can "fork" an example and modify it. I think it would be extraordinary if for an OpenGL example - run it, and run some commands with it (such as press and hold w key for 5 seconds) record it and show it to the user. I think something like this would have to be queued but I think it could provide an amazing new experience to people. I write something simple - then you fork it add some stuff - then I fork it etc etc.

So... compile locally, upload feedback to remote users from local machine? Due explain, sounds interesting.

Please elaborate in a bit more detail how you think something like this will work. I'm getting pretty interested in this project idea.

Pages: [1] 2 3 4 5 6 ... 124

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 PM]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 PM]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 AM]


Updates by Nathan
[October 30, 2015, 08:27:36 PM]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 PM]