![]() |
|
Virtual Screen for starters... |
Hans Spirit
Member #8,650
May 2007
![]() |
Hi, I need some help with virtual screen. I started using allegro for a month now and hadn't had any problems with it until I tried to use virtual screen. I tried to use MAX_X = 800 Then I just couldn't start my program Thanks anyway My Project: |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Yeah, the Virtual screen is a hold over from the DOS days. Its basically only supported in DOS and possibly linux console, where it creates a "Screen" thats larger than the mode, and allows you to scroll. -- |
Elverion
Member #6,239
September 2005
![]() |
The virtual screen, as Thomas Fjellstrom said, really isn't used anymore. There really is no need for it anymore. You can just keep track of world coordinates for your game objects, then draw everything by translating by those coordinates. I make use of a 2d camera class for this, since it makes things a bit easier. If you would like, I can give you the source for the camera class I've made. -- |
Hans Spirit
Member #8,650
May 2007
![]() |
If you please My Project: |
HardTranceFan
Member #7,317
June 2006
![]() |
We can see your avatar, if it's a single image (i.e. not an animated gif) -- |
Elverion
Member #6,239
September 2005
![]() |
camera.h
camera.cpp
In case you are wondering about the rects, they are just simple classes with double x,y,w, and h.
So basically, the "view" of the camera is just a rectangle that encompasses the map. Generally, you go from (0,0) to (map_width, map_height) where map's width and height are in pixels. So far it's sounding pretty complicated I assume, but just check the example and you'll better understand. Example:
There are some things to note. Do not actually try to compile the example. It won't run as-is due to missing code segments (obviously). You do not need to check and make sure your camera is within view. It does that automatically when using update or set. -- |
Matt Weir
Member #7,476
July 2006
![]() |
To take it even further I would make the camera a game object like a player, enemy, magic donut etc. This way it's trivial to create multiply cameras, cameras that move realistically, cameras with AI etc. The camera can have physics like a game object so as the player moves away from the center the camera will accelerate to catch up, a simple effect that makes things much more interesting. |
Hans Spirit
Member #8,650
May 2007
![]() |
Wow thanks a lot. I'm sure this will help. Now i just got to study it, and make one of my own to understand the idea. Thanks a lot for the help again. My Project: |
clovekx
Member #3,479
April 2003
![]() |
It's not a good OO practice to have a public variables in a class. Rather make them private and use get_variablename() method. Sure this takes more time to write, but it is cleaner and easier to maintain. --- |
ImLeftFooted
Member #3,935
October 2003
![]() |
Quote: Sure this takes more time to write, but it is cleaner and easier to maintain. I'd say its uglier and harder to maintain. The benifit as I see it is scalability. Later on you may want to set an allowable range for an attribute or something. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: It's not a good OO practice to have a public variables in a class.
It depends. class cFoo { private: int a; public: int get_a() const { return a; } void set_a(int _a) { a = _a; } }; Even Java allows public member variables. Plus over-OO-ing things isn't good either. There was this story on worsethanfailure.com where they had a pacman clone that used a few thousand threads and required a 3 GHz CPU to be playable; all that due to a strict OO design. --- |
Michael Jensen
Member #2,870
October 2002
![]() |
Actually, it wasn't the OOP that slowed the game design down, it was the fact that every sprite object allocated, and used it's own thread to keep track of animation, etc -- even the dots... I agree though, unless you have special needs on a variable (ex: it has a range, or you can't just let the programmer modify it anytime he pleases) make it public. Private should only be for things that you want to protect, or execute logic on when they change, etc...
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
You don't know if you won't need to provide special cases on variables/properties. Thats why its best to start with the access routines. so the API/ABI stays 100% consistent throughout the process. imo. -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: Actually, it wasn't the OOP that slowed the game design down, it was the fact that every sprite object allocated, and used it's own thread to keep track of animation, etc -- even the dots... Which, one could argue, is a case of encapsulation-to-the-max. Each objects runs in its own "world". Quote: You don't know if you won't need to provide special cases on variables/properties. Thats why its best to start with the access routines. so the API/ABI stays 100% consistent throughout the process. imo. Generally, yes. But for some kinds of classes (I like to call them "data classes"), some parameters can be set freely to anything by design. Examples are implementations of 3d vectors, fractional numbers, ... - using getters / setters on these makes things more clumsy without adding anything. Observe: class vec3d { public: float x; float y; float z; vec3d(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} vec3d(const vec3d& rhs): x(rhs.x), y(rhs.y), z(rhs.z) {} // ...snip... }; vs.:
And there is not a single value you wouldn't possibly want in a vector. --- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
That's quite thread unfriendly. -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Haven't done any proper multi-threaded stuff yet, so I wouldn't really know. What exactly is the problem here? --- |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: And there is not a single value you wouldn't possibly want in a vector. What about NaN or Inf? Or where vec3d.magnitude() > FLT_MAX? -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
You wouldn't want these in a float either. Something like a vec3d::contains_nan() method would be useful though. --- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote: What exactly is the problem here? Threads accessing and changing the var at the same time can cause problems. If say you're checking for something, between the check and the execution of the code, the var could be changed and no longer actually be within the range that was checked for. -- |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote:
You wouldn't want these in a float either. Something like a vec3d::contains_nan() method would be useful though. Depending on how it's used:
If you use a vector's magnitude a lot compared to how often it's changed, it'd be more efficient to calculate it when the vector changes, instead of when you need it. Or optionally you could set a flag when x, y, or z changes and when the magnitude is requested, update it if it's "dirty". -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Yes, if I needed the magnitude a lot between subsequent changes, then I would probably go for the "dirty" approach, which would of course involve getters/setters. Quote: Threads accessing and changing the var at the same time can cause problems. If say you're checking for something, between the check and the execution of the code, the var could be changed and no longer actually be within the range that was checked for. And how would I avoid that using getters/setters? Can't I just lock / mutex / whatever the entire vector before accessing it? --- |
|