|
pblais wrote: I don't have anyway to handshake with this device/application.
pblais wrote: when I tried running my app in one of the newer PCs
pblais wrote: Now my Sleep()'s are too short.
Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
Otherwise at some point your application will be Sleep()ing with the fishes.
led mike
|
|
|
|
|
led mike wrote: Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
And use a trackbar for fine-tuning!
|
|
|
|
|
led mike wrote: Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
I like that idea... How would I make configurable?
|
|
|
|
|
pblais wrote: How would I make configurable?
Instead of Sleep(100)
something like this:
Sleep( Config.Milliseconds);
where the number in that variable is provided by a user or administrator.
led mike
|
|
|
|
|
|
I wonder if he wants special sauce on his Fish Filet?
led mike
|
|
|
|
|
The whole thing brings back memories of my first computer job - interfacing with a
home-brewed laser scanner. All the magic numbers in the legacy code, and how the new 386
CPU messed it all up LOL! To this day, it's still referred to (by myself and my business
partner, who worked with me then) as the Laser Bread Slicer (that, we figured, was the extent of
its accuracy).
So, typical tech support goes something like "See the edit box labeled 'Fudge Factor'? Try
entering 203 insead of 198 and see if that fixes it."
Thanks man...I thought I had successfully repressed those memories
|
|
|
|
|
As has been said, the number you pass to Sleep() is just a request. Your thread might not wake up for a minute if some high-priority thread grabs the CPU. Something more accurate than Sleep() seems to be in order, check out multimedia timers and waitable timers.
|
|
|
|
|
Hi, maybe a silly question but:
My resource file, each time it auto-generates, includes windows.h. I need it to include afxcmn.h instead. I can of course change it manually but then each time I use the resource editor the .rc file generates again with windows.h and overwrites the manual change to afxcmn.h. How do I fix this? It's saying Generated from the TEXTINCLUDE 2 resource, maybe I can find/edit that? I have no idea what it is.
Thanks!
KR
|
|
|
|
|
|
Ok I got it to work, thanks.
KR
|
|
|
|
|
I'm having trouble adding inheritance into my program. First here is my code so far:
#include <GL/glut.h><br />
<br />
class Character<br />
{<br />
protected:<br />
int width, height;<br />
int tileX, tileY;<br />
float x, y;<br />
float speed;<br />
public:<br />
Character(float xPos, float yPos);<br />
Character();<br />
~Character();<br />
void draw();<br />
void move(int direction);<br />
float getX();<br />
float getY();<br />
};<br />
<br />
#include "Character.h"<br />
<br />
Character::Character(float xPos, float yPos)<br />
{<br />
width = 50;<br />
height = 50;<br />
x = xPos;<br />
y = yPos;<br />
speed = 0.5;<br />
}<br />
<br />
Character::Character()<br />
{<br />
}<br />
<br />
void Character::draw()<br />
{<br />
glColor3f(1.0, 0.0, 0.0);<br />
glPushMatrix();<br />
glTranslatef(x,y,0);<br />
glBegin(GL_QUADS);<br />
glVertex2d(0, 0);<br />
glVertex2d(0, height);<br />
glVertex2d(width, height);<br />
glVertex2d(width, 0);<br />
glEnd();<br />
glPopMatrix();<br />
}<br />
<br />
void Character::move(int direction)<br />
{<br />
if (direction == 2)<br />
{<br />
x -= speed;<br />
}<br />
else if (direction == 1)<br />
{<br />
x += speed;<br />
}<br />
else if (direction == 3)<br />
{<br />
y += speed;<br />
}<br />
else<br />
{<br />
y -= speed;<br />
}<br />
}<br />
<br />
float Character::getX()<br />
{<br />
return x;<br />
}<br />
<br />
float Character::getY()<br />
{<br />
return y;<br />
}<br />
<br />
#include <GL/glut.h><br />
#include "Character.h"<br />
<br />
class Alien : public Character<br />
{<br />
public:<br />
Alien(float xPos, float yPos);<br />
};<br />
<br />
#include "Alien.h"<br />
<br />
Alien::Alien(float xPos, float yPos)<br />
{<br />
width = 50;<br />
height = 50;<br />
x = xPos;<br />
y = yPos;<br />
speed = 0.1;<br />
}<br />
I thought this was adequate to get Alien to inherit all of the methods of Character, but I get the following errors:
error C2011: 'Character' : 'class' type redefinition
error C2504: 'Character' : base class undefined
error C2039: 'draw' : is not a member of 'Player'
error C2039: 'draw' : is not a member of 'Alien'
and so on. Any ideas what I am doing wrong? Thanks.
|
|
|
|
|
Don't forget to add the precompiler directive at the top of your header files so that they are included only once:
#ifndef MYFILE_H
#define MYFILE_H
#endif
|
|
|
|
|
Ah this fixed it. May I ask what these lines actually do? I've seen these a few times.
|
|
|
|
|
They just prevent that your header file is included several time (thus avoiding a redefinition of an existing class).
Basically, when you do an include, the precompiler will replace the include directive by the contents of the included file. Thus, in certain condition it can happen that you include the same file from different files (if two files include the same file and they are both included in another file).
|
|
|
|
|
I think your problem is that Character.h is being included more than once. Generally, header files are wrapped in something like
#ifndef CharacterClassInclusionGuard
#define CharacterClassInclusionGuard
class Character ( etc)
#endif
What's the other include you have in the header ? Is it stdafx.h ? That should be in the cpp.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
To complete Cedric and Christian answers, there's a Microsoft specific precompiler command that does the same thing, plus an additional check that permits a file not to be inserted (at least tried to be inserted) twice.
at the beginning of the header file you write, you can instead write this :
#pragma once
and that's all.
but don't forget it's microsoft specific, so if you plan to port your code to any other compiler, prefer using the other syntax
|
|
|
|
|
I’m making my first dive into what I’ve heard called “functionoids” or “functoids” (function pointer flexibility without the ‘static’ limitations). So far, so good…
All of the included code works great; that is, until I attempt to access members of the class Foo via a call to my “function pointer”. The ‘this’ pointer allows access to members of Foo::func1; ok fine, that makes perfect sense. But I want to reference members of Foo from the “functionoid” and don’t know how.
What am I missing?
Foo.h:
class Functionoid
{
public:
virtual void go() {}
};
class Foo
{
public:
void MainProc();
bool var;
class func1 : public Functionoid
{
public:
virtual void go();
};
};
Foo.cpp:
#include "Foo.h"
Foo::func1::go()
{
if (this->var)
0;
}
void Foo::MainProc()
{
Functionoid* pf1 = new func1;
pf1->go();
delete pf1;
}
-- modified at 15:37 Tuesday 13th February, 2007
|
|
|
|
|
You can't access any Foo members without an object of type Foo.
Nesting the func1 class declaration in Foo doesn't grant it any access to Foo's members (no
members exist without an object anyway).
How does this work... "Functionoid* pf1 = func1;"
Assigning a pointer from a class name? Maybe there needs to be a member object of type Foo::func1
in the Foo class?
Mark
|
|
|
|
|
Mark Salsbery wrote: How does this work... "Functionoid* pf1 = func1;"
Sorry, that should have read:
Functionoid* pf1 = new func1;
Mark Salsbery wrote: Nesting the func1 class declaration in Foo doesn't grant it any access to Foo's members
I understand that the code as written doesn't work ... my question is this: Is there a way I can change the aforementioned code such that- I might retain the non-static function pointer features, and
- have access to Foo's members?
|
|
|
|
|
I don't know how you'd do that. You need an object to access an object's members.
Nesting a class affects its scope, but not member access.
Functionoids can have constructor though, so an object can be passed:
class Functionoid
{
public:
virtual void go() = 0;
};
class Foo
{
public:
void MainProc();
bool var;
class func1 : public Functionoid
{
Foo &foo;
public:
func1(Foo &fooref) : foo(fooref) {}
virtual void go();
};
};
void Foo::func1::go()
{
if (foo.var)
{
}
}
void Foo::MainProc()
{
Functionoid* pf1 = new func1(*this);
pf1->go();
delete pf1;
}
|
|
|
|
|
That did it!
I'm new enough to C++ to be not-quite-sure what's going on with the "&foo" and " : foo(fooref)" business, but ignorance forces a pursuit of knowledge, so off to the old textbooks I go.
I'll be smarter tomorrow. Thanks!
|
|
|
|
|
quasinormalized wrote: not-quite-sure what's going on with the "&foo" and " : foo(fooref)" business
Since an object is required to have members to access, I chose to pass an object reference.
It could have been a pointer as well.
Warning:
With this method, if the Foo object referenced by the Foo::func1 member (Foo::func1::foo) goes
out of scope or is deleted, then subsequent calls to the go() method will fail if go() trys to
use foo.
In other words, it's up to you to track the lifetime of all objects involved
|
|
|
|
|
hi
i want to convert
String^ abc = "Hello world"
to
char *
or
char []
any idea how to do it?
|
|
|
|
|