Jump to content

  • Log In with Google      Sign In   
  • Create Account

fastcall22

Member Since 04 Feb 2008
Online Last Active Today, 05:22 PM

#5223732 FastCall Is Alll

Posted by fastcall22 on 16 April 2015 - 11:06 AM

omg dsm-senpai noticed me ohmy.png

It was written in response to dsm's affection to trigraphs. I figured, why stop at trigraphs? Here's teh code. There's still room for "improvement," but whatever:

http://ideone.com/1lnIcm
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <string>
#include <iterator>
 
#define mod %
#define div /
#define mul *
#define add +
#define sub -
#define insert <<
#define extract >>
#define shl <<
#define shr >>
#define bor |
#define band &
#define bxor ^
#define bnot ~
#define ptr *
#define assign =
#define equal_to ==
#define addr_of  &
#define open_paren (
#define open_bracket [
#define open_brace {
#define open_angle <
#define less_than <
#define close_paren )
#define close_bracket ]
#define close_brace }
#define close_angle >
#define greater_than >
#define comma ,
#define call ()
#define member .
 
#define block_begin {
#define block_end }
#define stop ;
 
int main open_paren int argc comma char ptr ptr argv close_paren
block_begin
	using namespace std stop
	string line stop
 
	while open_paren
		cout insert "\n> " insert flush and
		getline open_paren cin comma line close_paren close_paren
	block_begin
		istringstream stream open_paren line close_paren stop
		auto vec assign vector open_angle int close_angle open_paren
			istream_iterator open_angle int close_angle open_paren stream close_paren comma
			istream_iterator open_angle int close_angle call
		close_paren stop
 
		sort open_paren
			vec member begin call comma
			vec member end call
		close_paren stop
 
		cout insert '[' stop
		if open_paren vec member size call close_paren block_begin
			copy open_paren
				vec member begin call comma
				vec member end call sub 1 comma
				ostream_iterator open_angle int close_angle open_paren
					cout comma ", "
				close_paren
			close_paren stop
			cout insert vec member back call stop
		block_end
		cout insert ']' insert endl stop
	block_end
block_end
Sample run:
> 9 4 -3 4 0 7 8
[-3, 0, 4, 4, 7, 8, 9]

> -3 4 7 10 9 6
[-3, 4, 6, 7, 9, 10]

> 4 3 1 5 7
[1, 3, 4, 5, 7]



#5223303 Constant Buffers Disappearing

Posted by fastcall22 on 14 April 2015 - 07:59 PM

How are you setting up your constant buffer? Are you filling it with DeviceContext.MapSubresource and are you attaching it to the shader via DeviceContext.VertexShader.SetConstantBuffer?
Is it disappearing randomly during the program, or before the very first frame?


#5218599 c++ count lines in txt file and then read these lines without reopening a file

Posted by fastcall22 on 23 March 2015 - 02:47 PM

omg wiredcat, pls


	// read
	size_t len = 0;
	char* str = read_all_text(path,&len);
	const char* end = str + len;

	// count and allocate
	size_t line_ct = count((const char*)str,end,'\n') + 1;

	size_t ldx = 0;
	const char** lines = new const char*[line_ct];

	// process
	lines[ldx++] = str;
	for ( char* p = str; p < end; ++p ) {
		switch ( *p ) {
			case '\n':
				assert(ldx < line_ct);
				lines[ldx++] = p + 1;
			case '\r':
				*p = 0;
				break;

			default: ;
		}
	}


	// beep boop
	for ( size_t idx = 0; idx < line_ct; ++idx )
		printf("%i %s\n",idx,lines[idx]);

	// clean-up
	delete[] lines;
	delete[] str;



#5218480 c++ count lines in txt file and then read these lines without reopening a file

Posted by fastcall22 on 23 March 2015 - 09:47 AM

If you only need read-only access to the file, then you can avoid quite a few dynamic allocations by reading the entire file into a string, then find and replace newlines with null-terminators, adding them to a list of const char*. And, it's trivial to count the number of lines beforehand, as you don't reprocess the file or read each line and immediately discard the lines.


#5217693 Doge Indirection

Posted by fastcall22 on 19 March 2015 - 12:56 PM

megafp2.png


#5215156 Logic for polygonizing lines where the polygon with multiple holes

Posted by fastcall22 on 07 March 2015 - 11:23 AM

You can use a library such as CGAL or use GLU's tessellators. The general approach seems to be to construct a Delaunay triangulation with all of the edges and then punch out the holes. As for determining what's in and what's out, use the winding order of the contour to determine whether or not it's adding or subtracting from the geometry.


#5214351 Convenient approach to composite pattern in C++

Posted by fastcall22 on 03 March 2015 - 08:26 PM

template<typename C, typename F>
static inline Caller<C, F> operator->*(C &c, F &&f) {


Yeah, okay. I'm totally okay with what just happened and am totally fine with how readable this is.

static ::operator->*... Yup!


#5214350 Source code with errors: http://ideone.com/eSWKwf

Posted by fastcall22 on 03 March 2015 - 08:16 PM

Okay.

First: Your code was mangled when you copy-pasta'd. Here is the cleaned up code.
Second: You're missing a '#' for the preprocessor directive #define.
Third: In C++, it's usually more pragmatic to use a constant over a macro, but each is acceptable: const int SIZE = 10;
Fourth: You're missing a closing brace for your for loop after line 33.
Fifth: This has nothing to do with "3D" or "game programming" :|


#5213014 Read data from specified adress of memory.

Posted by fastcall22 on 25 February 2015 - 09:26 PM

(I think he's asking why he can't deref a void pointer.)

Then you still need to memcpy, because you cannot what to write without knowing the type, unless you store this information elsewhere:
void do_the_thing(void* write_to, const void* read_from) {
    // Nope!  How many bytes do we write?  What about copy constructors or move constructors?
    // *write_to = read_from;

    // Ok, but dangerous -- you don't know if either are Foobars and you might violate the rule of 3
    memcpy( (char*)write_to, (const char*)read_from, sizeof(Foobar) );

    // Ok, but dangerous -- you don't know if either are actually Foobars
    *reinterpret_cast<Foobar*>(write_to) = *reinterpret_cast<const Foobar*>(read_from);
}

int whatever(const Foobar& foo_a, Foobar& foo_b ) {
    const void* read_from = &foo_a;
    void* write_to = &foo_b;
    
    // sometime later...

    do_the_thing(write_to, read_from);  // Ok, both are Foobars

    const char* str = "Hello there";
    int truth = 47;
    do_the_thing(&str, &truth); // so many levels of wrong
}
EDIT:
This is also assuming that he isn't trying to ReadProcessMemory or WriteProcessMemory.


#5213011 Read data from specified adress of memory.

Posted by fastcall22 on 25 February 2015 - 09:09 PM

He doesn't want to read and write, he wants to read and write.


He doesn't want to "he doesn't want to read and write, he wants to read and write", he wants to "he doesn't want to read and write, he wants to read and write" with variables.


#5212635 Subtraction Problem in Java

Posted by fastcall22 on 24 February 2015 - 12:26 AM

floating point arithmetic anything in Java anything is an approximation


FTFY. Even in math and science, 1.333e0 + 1.333e1 will result in some loss in precision (1.466e1 != 1.4663e0), for four significant digits. Floating point math is no different.

EDIT:
I can't math. sad.png



#5211320 Programmatically search .fla Flash file for imported component

Posted by fastcall22 on 17 February 2015 - 07:29 PM

The problem is that flash files are in binary, and you're attempting to read them as text, which is a big no-no (in the general case). I'm assuming that you are only attempting to identify files having the component and nothing more. If this is the case, then you may be able to use any text editor with a "find all in files" feature.


#5204254 Rendering .obj Model in DirectX 11

Posted by fastcall22 on 14 January 2015 - 12:09 PM

Have you tried turning it on and off again?


#5199652 Boost c++ How to Deserialize Element of Container

Posted by fastcall22 on 23 December 2014 - 01:56 AM

Use an index table.

1. Reserve some space at the beginning of the file for the index table.
2. Serialize each entity, noting the write position of the stream, and store that and the entity ID into the table.
3. After serializing the entities, sort the table by entity ID.
4. Write the number of entities and the contents of the table to the beginning of the file.

When looking for a specific set of entities, all you'll need to do is to read the entire index, binary search for the entity IDs you're looking for, set the read position of the stream, then deserialize the entity. smile.png


#5199218 Chess moves

Posted by fastcall22 on 20 December 2014 - 12:43 AM

That is very disappointing. I guess I'll have to find some other programmer use for a 5TB external hard drive.

Oh, I know!! How about...

...

...
 
Spoiler





PARTNERS