|
I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function .
I want to know how to implement anf declare this function . Beside that , I corrected the rest of code
|
|
|
|
|
There does not seem to be a Rectangle::printFourVertices() method. There is a redundant assignment operator in the Point::setX() method.
Short of that, what's the issue? "I am getting errors" is meaningless.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function .
I want to know how to implement anf declare this function . Beside that , I corrected the rest of code
|
|
|
|
|
How would you do it using pencil and paper? If you coded up everything that calculates said vertices, printing them should be a non-issue, yes?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello. It my first message here, I'll try to do it the right way.
The programming is my hobby (MinGW 32bit). About topic. I would like to represent my C++ code for buffer scroll. Perhaps I designing another bike, but still... What I mean about scrolling. For example, I have some buffer in which data starts somewhere in the middle:
char * buffer = "World!Hello, ";
But I need:
char * buffer = "Hello, World!";
So I need to cut out data at the end, move the rest of data to the end of buffer and paste cutted data to the beginning. This is "lossless buffer scrolling" of what I am talking about.
This is a trivial job if ones use temporary buffer not less than half of the *buffer's length, few memcpy() statements and so on. But this is not my case.
Condition 1. Source buffer size is very large (1/2 or 2/3 of total physical ram). So it is not good idea to allocate temporary buffer.
Condition 2. I can not use data storage like HDD drive. I can not use any kind of swap techniques. (It will produces temporary system freeses.)
Condition 3. I am not what to use virtual addressing techniques to virtually scroll buffer.
Condition 4. The buffer size and scroll distance is arbitrary (sets as function parameters).
So I created a scrolling buffer by permutation, which source code I would like to public. It is quite tested by brutte-force method (buffer size and scrolling distance were alternated, the result is compared with alternative scrolling techniques). In my opinion, the implementation of the method is unusual (or, at least, interesting).
Here it is:
namespace CommonTools
{
#ifdef DEBUG
uint32_t scroll_raw_buffer_last_rounds = 0;
#endif
void scroll_raw_buffer (void *data , const uint32_t buffer_size, uint32_t distance)
{
#ifdef DEBUG
scroll_raw_buffer_last_rounds = 0; #endif
if (buffer_size >= INT_MAX)
throw CommonTools::Errors::Simple (CommonTools::Errors::StE_Overflow, __PLACE__);
if ( (!data) || (buffer_size < 2)) return;
distance %= buffer_size;
if (!distance) return;
TRAP_in_DEBUG (distance >= buffer_size, msg_interror)
uint8_t *buf = (uint8_t *) data;
const uint32_t shift_value = distance;
#ifdef DEBUG
static const size_t max_stack_buffer = 256;
#else
static const size_t max_stack_buffer = 1024;
#endif
if (buffer_size <= max_stack_buffer)
{
uint8_t *tmp_buf = (uint8_t *) alloca (buffer_size);
memcpy (tmp_buf, buf, buffer_size);
memcpy (buf + shift_value, tmp_buf, buffer_size - shift_value);
memcpy (buf, tmp_buf + buffer_size - shift_value, shift_value);
return;
}
#ifdef DEBUG
scroll_raw_buffer_last_rounds = 1;
#endif
uint32_t bytes_left = buffer_size, bytes_per_round = 0;
uint32_t total_rounds = 0;
uint32_t round_number = 1; uint8_t *next_data_buffer = 0;
uint32_t dest_index;
#ifdef DEBUG
const uint8_t * const out_of_buffer = buf + buffer_size;
#endif
do {
{
const uint32_t round_start_offset = round_number - 1;
dest_index = round_start_offset;
if (dest_index >= buffer_size) dest_index -= buffer_size;
uint8_t next_data = buf[dest_index];
do
{
dest_index += shift_value; if (dest_index >= buffer_size) dest_index -= buffer_size;
register uint8_t &destination = buf [dest_index];
swap (destination, next_data);
bytes_left--;
}
while (dest_index != round_start_offset);
}
if (!bytes_left) break;
if (round_number == 1)
{
bytes_per_round = buffer_size - bytes_left;
total_rounds = buffer_size / bytes_per_round;
#ifdef DEBUG
scroll_raw_buffer_last_rounds = total_rounds;
#endif
TRAP_in_DEBUG (buffer_size % bytes_per_round, msg_bogus_state)
}
round_number++;
if (!next_data_buffer) next_data_buffer = (uint8_t *) alloca (max_stack_buffer);
for (;round_number < total_rounds;) {
const uint32_t rounds_left = total_rounds - round_number + 1;
const size_t block_size = min_ct (max_stack_buffer, rounds_left);
const uint32_t round_start_offset = round_number - 1;
dest_index = round_start_offset;
if (dest_index >= buffer_size) dest_index -= buffer_size;
TRAP_in_DEBUG (buf + dest_index + block_size >= out_of_buffer, msg_interror)
memcpy (next_data_buffer, buf + dest_index, block_size);
TRAP_in_DEBUG (bytes_left < bytes_per_round*block_size, msg_interror)
do {
dest_index += shift_value; if (dest_index >= buffer_size) dest_index -= buffer_size;
register uint8_t *destination = buf + dest_index;
memswap (destination, next_data_buffer, block_size);
} while (dest_index != round_start_offset);
bytes_left -= bytes_per_round * block_size;
round_number += block_size;
} } while (bytes_left > 0);
return;
}
}
Important notes:
1. If ones need negative direction you can use distance=buffer_size-1 as -1 direction.
2. swap() is just variables swapping, min_ct() function returns the minimum value from two arguments.
3. TRAP_in_DEBUG() or TRAP() are macroses to terminate program with message if first parameter is true (message is in 2nd parameter, like ASSERT() but little different way).
4. Function has size limit of scrolling buffer (up to INT_MAX, about 2 Gb in my case).
5. If someone would like to use this code, I will be pleasured if my name is mentioned somewhere in credits..
Echo7
modified 22-Jul-17 11:27am.
|
|
|
|
|
|
Quote: This looks more like a Tip than a question and would be better posted at Submit a new Article[^].
I'll do it, when I have read about rules.
Echo7
|
|
|
|
|
yes it belongs in tips but I also have a little tip for you.
memmove from the C/C++ standards library can deal with source and destination memory overlapping and it can do it with no extra buffers at all.
So you really only need the string search parts of your code and then use memmove to do the shuffle replacing the memcpy's
memmove[^]
memmove ensures that the original source bytes in the overlapping region are copied before being overwritten.
It was probably a good learning excercise and you can rate how you went against a standards library and here is the code
public source Implementation of memcopy[^]
It's never wasted time to learn the standards libraries
In vino veritas
modified 22-Jul-17 7:22am.
|
|
|
|
|
Quote: memmove from the C/C++ standards library can deal with source and destination memory overlapping and it can do it with no extra buffers at all
I know it. But I can not implement memmove() to my task. memmove() will ovewrite some part of my buffer (or I have to use temporary buffer to store that part) so I'll loose some data. Perhaps there is a way to use it, but I do not yet know how.
Quote: you really only need the string search parts of your code
char * buffer = "World!Hello, ";
It was only the small example to illustrate what I meaning under "buffer scrolling" term. In real code I have more that 100Mb binary (non-text) raw data which I have got from external device.
I do not know (in advance) the size, and I do not know the move distance.
Echo7
modified 22-Jul-17 11:21am.
|
|
|
|
|
SOCKETS - SERVER & CLIENT in c++ code for making a project on server & client site plzzz tell me
|
|
|
|
|
Use any boost or Qt libraries. They both offer networking capabilities for your applications, that you can use and build the apps that support networking features. Server and clients are just the applications that either take control of communication, or are guests. Network Examples | Qt Network 5.9 see this for examples on this. They might have something as a working sample, but you will still require some tweaks.
One thing, do not go onwards toward ACE framework — it is just painful, I am currently trying to get it to work and say hello, but it does not even work at all. If someone ever offers you the code, just away from it.
Qt | Cross-platform software development for embedded & desktop
Boost C++ Libraries
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Single Server With Multiple Clients : a Simple C++ Implementation[^]
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Read #2 here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi
I found the source of problem the exception occurred when I did CAsncSocket::Receive(CString*,int) I has previously done a GetBufferSetLength to a large enough size so I don't
understand why I got an exception
|
|
|
|
|
Check the documentation: CAsyncSocket::Receive[^]. The first parameter should be a pointer to a byte buffer, which CString* is not.
|
|
|
|
|
The CString class is not thread safe but using CAsyncSocket indicates that you are using multiple threads.
When using GetBuffer[Xxx] , the string object is locked until ReleaseBuffer is called (which must be called from the same thread).
As Richard already noted, you need a byte buffer. While this can be achieved by using CStringA , I recommend to rethink your design. Don't use string classes for binary data and ensure thread safety.
|
|
|
|
|
Are you to
CByteArray if so how can I ensure the size
|
|
|
|
|
You should just use a simple array of bytes, which is what the socket method requires.
|
|
|
|
|
You probably don't need an array class if you just want to copy data and do not need inserting or removing of items. If you know the (max.) size in advance just use a plain array allocated with new . If not, you can still grow by allocating a new array, copying data from the old, and delete the old.
CByteArray is also an MFC class which is probably also not thread safe. But it is impossible to help without knowing what your code is doing.
The question are (you may ask and solve them yourself):
Does my array require special modification functions besides copying?
Which functions use my array under which conditions (read only, write only, both)?
Where is may array allocated (this might be at different code points if resizing is necessary)?
Where it is deleted?
Do I need thread safety?
|
|
|
|
|
I'm reading this excellent book. I considered to use steering behavior in our MMORPG game server project.
but if we use it all,it would consume a lot of cpu time which would be unacceptable for a server project.
does any one have any experience on this topic?How could I find a proper way to use steering behavior in MMORPG server?
Thank you very much.
|
|
|
|
|
You write the search algorthim as an iteration, with adjustable resolution and trigger(s).
If two objects are more than X apart the search doesn't run at all unless there is a special trigger. If you haven't been "spotted" there is no need for an enemy to search and so they usually just walk a defined set of waypoints called "pathing".
So movement especially for NPC's or bots usually have two different behaviours being "pathing" and "searching". Often there is also a way to get "unspotted" and NPC's/BOTs may be leashed to some co-ordinate. If they get more than some distance from the leash point they will drop "seaching" behaviour and resume "pathing".
The trigger whatever that is usually establishes the "target" and it is at that point the search AI kicks in. The game design thus far made sure searching is used sparingly.
Now when the search algorthim kicks in, it sets a resolution grid based upon how far the target is away. You don't need a fine grid for a target far away. So you will have a raycast which you run to each point on the grid. So when target is a long way away you still only get a small grid just they represent a big distance. That is the bit your code you currently have probably doesn't do and so you have a huge grid when the target is a long way away.
So now with your grid you run the AI search algorthim to work out what direction to move to the target allowing for walls etc. If the target is a long way away the direction will only be rough but that is all it needs it will fine up as it gets closer.
The problem you probably have with the AI search they have given you is the grid is massive and it gets bigger and bigger the further a target is away.
That would be how the vast majority of games not just MMORPG games work. Suggested start point for reading
Near-Optimal Hierarchical Pathfinding (HPA*) | AiGameDev.com[^]
In vino veritas
modified 20-Jul-17 3:34am.
|
|
|
|
|
thank you very much,it's really a great help.
there is a lot of work to do
|
|
|
|
|
Hi
I am getting a heap corruption as indicated by the message in quotes to my VS output debug window
At first I tried gflags from the command line and did a full enable for my application or my image
As I read up on gflags it puts a extra block of storage (that's is protected) between every allocation
I have what I think is a pretty big machine 64 gb of ram, While running the program I quickly got a message that I was out of storage
I am wondering if there is anything I can do programmatically to invoke gflags
As I have an idea in what part of the program this happening
I allocate storage for a dialog derived object via new
upon receiving a tcp/ip message in a modeless dialog I do a create for derived Cdialog for which I previously did the "new"
it is after do the create of the dialog and populate the control including allocating via new a Richedit and streaming data to it that something goes wrong all storage is allocated via
new
I am thinking maybe I can track this down with HeapValidate putting it various pots in this path of code and checking the return code
Thanks
|
|
|
|
|
I don't know how to do what you want with heap but there is an obvious way to make the program more deterministic which is to pre-create the dialogs just held in a storage array not in use. It is really dangerous to be creating anything so significant off an event.
When you get a message you call your little routine to pass you back the first free dialog which you load and use. When it's finished you put it back in the pool.
It's a lot easier to avoid such problems by changing behaviour to determinstic rather than chase the bug itself
In vino veritas
|
|
|
|
|
Leon
I don't know if that's an option the dialog has a number of controls including a richedit which can be filled with a number of text lines
Would going down the path of using the functions in this article help me track down my problem
CRT Debug Heap Details[^]
|
|
|
|