|
Screen Update API: final draft |
23yrold3yrold
Member #1,134
March 2001
|
EDIT: See posts below for the latest attached update Keen observers may have seen this already. I want to submit my screen update API too, so I gave it a quick once-over and added some new functionality, and made it as C friendly as I can. I'd like the code checked over before I formally submit it though, since it's longer (and the possibility that I missed a bug has thus gone up), but especially since I want to make sure it's okay for use in C programs (and for the life of me, I can't get my makefile to compile C source to check for myself). I'm pretty sure some sort of extern C should be in there somewhere, but I forget what and where. The source is pretty condensed; less than 300 lines of code total across 3 files (implementation .cpp, declaration .h, and the main .cpp example program). Just for kicks, I also set the color depth and default update method using a config file, if that sort of idea appeals to you. Thanks for your time. -- |
Richard Phipps
Member #1,632
November 2001
|
Looking good! But change the BOOL type to char to make it work with C.
|
23yrold3yrold
Member #1,134
March 2001
|
You mean the waitforvsync variable? Good point. I changed the updatemethod variable to char too, just because. Also, I assume // comments are okay? And what about extern C; do I still have to do that somewhere? I expected more feedback. Thanks for checking it, RP. -- |
Richard Phipps
Member #1,632
November 2001
|
// comments were adopted as part of the c99 standed (I think), anyway I use them and they are ok. Sunday is always a bit quiet.. |
axilmar
Member #1,204
April 2001
|
Here is my own screen update API, complete with support for DRS (with a very fast clever system that avoids blitting of the same area twice without using rectangle combining/splitting) as well as all the traditional methods for screen updating, along with a little DRS demo. EDIT: I forgot to say that it also includes support for writing balanced game loops (the known algorithm in the Allegro FAQ), and that it is 283 lines of code, non-condensed, containing comments for Doc++ (you can find the reference at doc/index.htm). |
spellcaster
Member #1,493
September 2001
|
axilmar: bad puppy. If you want to present your api, create your own thread. Stop that BAFism now. 23: You should check if cplusplpus is not defined: #ifndef __cplusplus extern "C" { #endif // ... #ifndef __cplusplus } #endif
-- |
23yrold3yrold
Member #1,134
March 2001
|
Right; that. So I should change the header to this?
And if the implementation file is a .cpp file (as it is now), that's not necessary, is it? If it's changed to a .c file, that's needed? I can't get my makefile to compile .c files so I can't check. axilmar makes a good point, that my API has no DRS. But a DRS can be built on top of it easily enough. I have no need for a DRS personally. Here's my makefile:
Here's my error: >make cc -c -o screen.o screen.c process_begin: CreateProcess((null), cc -c -o screen.o screen.c, ...) failed. make (e=2): The system cannot find the file specified. make: *** [screen.o] Error 2 >Exit code: 2 Anyone help me? -- |
Richard Phipps
Member #1,632
November 2001
|
Quote: %.o : %.cpp *.h Change to: Quote: %.o : %.c *.h ? |
flares
Member #3,463
April 2003
|
here's my error said: >make cc -c -o screen.o screen.c process_begin: CreateProcess((null), cc -c -o screen.o screen.c, ...) failed. make (e=2): The system cannot find the file specified. make: *** [screen.o] Error 2 >Exit code: 2
1. are all your files cpp sources or is there c source ones too? [nonnus29]Plus the api is crap ... I'd rather chew broken glass then code with those. |
Oscar Giner
Member #2,207
April 2002
|
If you want to be able to compile .c and .cpp files in a same project, just have this in your makefile: $(OBJ_DIR)/%.o: src/%.cpp g++ $(CFLAGS) -o $@ -c $< $(OBJ_DIR)/%.o: src/%.c gcc $(CFLAGS) -o $@ -c $< works for me -- |
23yrold3yrold
Member #1,134
March 2001
|
Same error; sorry. Maybe I just don't have cc.exe ... or gcc ... or something ... -- |
Rash
Member #2,374
May 2002
|
/me sees the following: #define TRIPLEBUFFER 1 #define PAGEFLIP 2 #define SYSTEMBUFFER 3 #define DOUBLEBUFFER 4
<C0CKS SHOTGUN> enum { TRIPLEBUFFER = 1, PAGEFLIP = 2, SYSTEMBUFFER = 3, DOUBLEBUFFER = 4 }; After that, I'm going after Matthew and his censorship filter. |
23yrold3yrold
Member #1,134
March 2001
|
Yeah, I considered that. Just didn't think it was a big issue; I thought everyone here loved #define. I'd make it this though ... enum { NOUPDATEMETHOD = 0, TRIPLEBUFFER = 1, PAGEFLIP = 2, SYSTEMBUFFER = 3, DOUBLEBUFFER = 4 }; ... because the invalid method is handy in screen.cpp. -- |
Rash
Member #2,374
May 2002
|
You might as well drop the values then as you're not using them. |
spellcaster
Member #1,493
September 2001
|
Quote: Yeah, I considered that. Just didn't think it was a big issue; It isn't a big issue. But you shouldn't use defines for constant values. -- |
Gnatinator
Member #2,330
May 2002
|
All hail Barry, King of the Kode! Nice work 23, this resource will prove useful to many.
|
ReyBrujo
Moderator
January 2001
|
23, define CXX as g++, by default it seems to be set to cc, which is a very old name of the GCC compiler (CXX = g++ at the begining of your makefile), as said above. If it stills triggers CXX, then use GCC instead of CXX, or just hardcode the compiler as Oscar suggested. -- |
23yrold3yrold
Member #1,134
March 2001
|
RB: No good. Okay, here's draft 2. The screen.cpp file is now a .c file, and I'm including no makefile, so if you can't compile it without error yourself, tell me why. If the code is all good, the subject of naming conventions may be introduced ... -- |
ReyBrujo
Moderator
January 2001
|
Ok, got the error. The problem is this rule: %.o : %.cpp *.h $(CXX) -o $@ -c $< Note that it tells how to compile cpp files, but you have c files, so the compiler goes to the implicit default rule for c files (which is legacy, using cc for compiling). So, change that rule to: %.o : %.c *.h $(CXX) -o $@ -c $< $(CFLAGS) And should work. -- |
23yrold3yrold
Member #1,134
March 2001
|
Hooray!
That did it. main.cpp and screen.c compile and link perfectly; thanks. -- |
ReyBrujo
Moderator
January 2001
|
I would use some different makefile, that creates a library and/or the example, like:
Also, my mistake in your previous makefile: Use all FLAGS or all CFLAGS, otherwise it would compile and link with different flags. Convention says you should use CFLAGS for C and CXXFLAGS for C++, but in this case it is up to you. -- |
axilmar
Member #1,204
April 2001
|
Quote: axilmar: bad puppy. If you want to present your api, create your own thread. Stop that BAFism now. Ok, if that's the proper way. |
Steve Terry
Member #1,989
March 2002
|
o_O there is competiton today of screen updaters I would post mine... but nah. Anyway my question is what is the advantage/reason for using enum instead of #define? ___________________________________ |
Kanzure
Member #3,669
July 2003
|
..edit.. Oh, and it just looks cooler to boot |
Thomas Fjellstrom
Member #476
June 2000
|
#define is pre processor based. they get replaced inline with the values before the compiler even gets the code. -- |
|
|