Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About forb

  • Rank
  1. Just assign the double to an int? The floating point value is instantly truncated without casts or (formal) conversions. inline int MyFloor(double d) { int f = d; return f; }
  2. forb

    C++ cvar system

    I've attempted this topic just recently myself. My solution came from making a map<string, cvar_t> where cvar_t is a struct that has pointer storage for a few basic types I needed, int*, double*, string*, a flag for the type of cvar it is (int, double, string) and finally the cvar's name. This sidesteps polymorphism but at only the cost of a few extra address variables. I then have functions that return the addresses of the cvar value itself, not the struct but the data type address in use based on the type flag, and the calling functions should know what type of cvar they're dealing with thus knowing which call to make in order to retrieve the proper address. By returning the address of the cvar's variable, you can reference it in multiple places. If it is changed in one place, its instantly changed in all the others (this is the primary advantage I see in doing it this way). An example would be if you had a renderer that had an int representing whether or not to draw polygons as wireframe or solids, and you change that variable in the console (assuming you did things correctly) the renderer will instantly start drawing wireframes based upon your input instead of having to query the cvar system for your variable on each pass to see whether it should or shouldn't draw wireframes. As for the processing from the console, I pass everything around as a string and convert to its actual datatype at time of assignment since the particular cvars have type flags. If I'm not mistaken, this is similar to how the quake engine handles cvars.
  3. Thank you, I'll look at this closer when I'm out of work. I was considering this as a workaround, it seems a little odd that I can't get the linker to just let it go. Bregma's post may shed some light on that. I was hoping to avoid having passing in a mess of references but I should still be able to hide the implementation from the end user this way so its an acceptable workaround.
  4. To do that would mean moving other things into the scope of the DLL which I also don't want to do. This functionality needs to be removed from the DLL so that the end users of my Class don't have to deal with explicitly defining and linking the Console portion of this application.
  5. When I include main.o in the linking, the linker then wants to know about all of the other objects used in that file. Aside from that, I don't want to roll the whole application into the dll.
  6. I'm trying to build a DLL and can't get it to link because of an undefined reference... please keep reading. I'm writing a program and I have the need to access functions that are only defined in the main.cpp source file from another source file. I declare a prototype in the header or source file in which I'll need to call the function, like so... extern void Con_print(const char* fmt, ...); When I try to link and create the DLL I get the following error: MyGame.o:MyGame.cpp:(.text+0xab): undefined reference to `Con_print(char const*, ...)` collect2: ld returned 1 exit status I'm using g++ to compile and link, in MinGW in Windows 7. Here is how I'm attempting to compile and link the DLL g++ -c -I"./headers/" src/Game.cpp -o Game.o g++ -c -I"./headers/" gameMod/MyGame.cpp -o MyGame.o g++ -shared -o MyGame.dll Game.o MyGame.o Here is the code in its simplest form: main.cpp ... void Con_print(const char* fmt, ...) { ... // func body ... } ... Game.h extern void Con_print(const char* fmt, ...); class Game { ... }; MyGame.h #include "Game.h" class MyGame : public Game { ... void example(); ... }; MyGame.cpp ... void MyGame::example() { Con_print("Here's my example: %s", "more input"); } ... From within MyGame->example(), I call Con_print as you can see above, this particular call is what the linker complains about, if I comment this call out (not the declaration) the DLL compiles normally and I am able to load it at runtime as expected. This functionality works perfectly in Linux (with dynamically loading of a .so) and I am able to call my externally defined functions, but I can't get the DLL built in Windows because of this 'undefined reference'. I've tried compiling this in Visual Studio 2010 Express and I get an identical error to that which I get from g++. I'm wondering if there is another way to build the DLL or if there is a way I can get g++ to let this undefined reference slide?
  7. Whoops, wrong forum, my bad.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!