• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About trajectorymodifier

  • Rank
  1. I've got a static library project in Eclipse that links against SDL and OpenGL - where can I define these links? In Project -> Properties -> C/C++ Build -> Settings -> Tool Settings there is no MinGW linker option like with executable projects; the rest of the tabs doesn't provide any relevant (...looking...) information either The project compiles fine, the errors I'm getting are Linker errors (undefined references to SDL and OpenGL functions)...
  2. gah. problem solved - Eclipse needed one more restart.
  3. As Windows is not my primary platform of development and I loathed the manifest + 6 flavors of runtime system that comes with MSVS (not to mention the several hundred megabyte SDK's), I've been using Dev-Cpp, which is highly deprecated. I've learned about Eclipse, which seems ever so sleek and today I've made my switch to it. I'm using SDL and OpenGL. I've found two tutorials, [1] and [2] on the subject, and they proved quite helpful. - I'm using the preprocessor symbol main=SDL_main (tried without, too) - I'm linking against mingw32, SDLmain, SDL (in the given order, however I've tried to switch around their precedence), tried the -mwindows flag (and without). - I'm keeping my SDL includes, libraries and binaries in MinGW's respective folders (although tried with them being kept separately), thus I'm not specifying their locations (elmininating the duplicate path entry warning)) However, when I'm trying to build the simple example, [source lang=cpp] #include <stdio.h> #include <SDL/SDL.h> int main(int argc, char* argv[]) { printf("Hello, SDL User!n"); if(SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Video initialization failed: %s", SDL_GetError()); return 1; } SDL_Quit(); return 0; } The compiler barfs at me as follows: /Users/hercules/trunk/SDL-1.2/./src/main/win32/SDL_win32_main.c undefined reference to `SDL_main' What on earth is causing this and how can this be fixed? (Yes, there is a similar thread, however it has been retired while the problem wasn't solved.) [Edited by - trajectorymodifier on June 20, 2009 7:56:28 AM]
  4. the reason for starting this noobly thread is because I've reached a certain degree of completion with my framework (well, 99.9% of what I want to use it for just now) and I'd like to recompile it or transform it into a library from the bunch of headers & source files it is at the moment. The framework is OpenGL / SDL (+ _Image, _Mixer) based, and I'd like to build the libraries for at least OSX, Win32(, Linux / GP2X, maybe). There's no multi-threaded functionality (EDIT: ... added -- there might be whatever multithreadedness (like in SDL_Mixer)). very little have I ever found on the topic, and would much appreciate some nudges in the right direction (links, recommended books, etc.): - what refactoring do I need to do, what will be the entry point of the library? (the only core functionality the framework has is to initialize SDL on startup (OpenGL is initialized by the graphics subsystem)) - how do I make sure that it dynamically links to the libraries / frameworks it depends on - whereas it'll be a .dll under Windows, what format should I go for under OS X? (.dylib, .framework, something else?) what are the differences? I understand that this is a huge topic to cover, and not expecting ready made solutions, but each and every bit of help would be great. (I'm just going through this: http://www.gamedev.net/reference/articles/article1583.asp ; hopefully it'll help too) [Edited by - trajectorymodifier on October 13, 2008 10:53:39 AM]
  5. how to go about platformer physics

    Quote:Original post by OrangyTang Quote:Original post by trajectorymodifier Awesome.=) In the meantime I've been checking out Snowman Village and I can see how this approach is versatile. I'm guessing Sega have used something similar in the Sonic games (man, how much I wondered how did they implement those loops), etc. Yeah, one of these days I'm going to have a crack at doing a proper Sonic clone with loops and corkscrews and all that jazz. I guess they do something similar, but with slightly more complicated 1d physics so you can fall off loops when going too slow or stick to it if you're going fast enough. Particularly in the later 2d games (Sonic 3, S&K) there's sequences where your character is "on rails" and following something more complex than the actual tile map, suggesting they've got invisible paths in the levels they're using for collision. I was hoping that these aren't necessary -- but for complex structures like those corkscrews the tile map certainly isn't enough information. It took me a minute or two to figure how to go about walls (vs floors) but I guess, collision detection mechanics work as normal whilst in "1d mode" - it's gravity that doesn't. In other words, I really only have to calculate the walkable surfaces. For huge stages, like those in Sonic, there must be some means to break down the map into smaller units; I can't see the engine traversing everything at every frame. Probably this is where a tile based approach will kick in, the tile being the size of the screen. (I'm guessing this will ultimately result in the sacrifice of the easily readable text-based maps I'm using.... or will it?) Funny to see the design fall back to something similar to rooms in those oldschool non-scrolling platformers.=) Quote:Original post by OrangyTang Quote:Original post by trajectorymodifier I'll think of something how to calculate these surfaces from tiles, as I want to keep redundancy to a minimum. For my shapes, I just store the vertices in a Ring container, then collision detection connects the dots for itself. But probably, in a game-specific use, the engine can create chains of surfaces from tiles that are adjacent... or dunno. Generating them from a tile map is certainly a good idea. For Snowman Village all the levels were randomly generated so I didn't need a level editor. For my current platformer I'm trying to use a vector editor for the maps but to be honest it's not working out particularly well and I'm thinking of switching to something tile-based and generating the collision surfaces from the tiles (either at level load or at compile time depending on how fast it ends up being). Oh yeah, I was about to start working on something I called a "generic format level editor". I'm so glad I didn't, yet.=) The objective is to provide a tool for creating huge maps of convex shapes that can be positioned freely, have an arbitrary number of sides, and can either be textured / plain. I was gonna start on using layers for parallax scrolling -- now this is something that's most probably killed by the "room" (screen-sized tile) approach, or is it? Well, up to now I didn't write a hell of a lot documentation... This is probably the point where I ought to start doing it...
  6. how to go about platformer physics

    Quote:Original post by OrangyTang When on the ground I like to store the player's position as relative to the current surface, so something like: *** Source Snippet Removed *** 'distance' is the distance along the surface segment, so moving just means adding your current speed to it. Then if it's less than zero, or greater than surface.length() you've stepped off the edge. Depending on your levels you might have surfaces represented as just single line segments, or if you need something more complicated then chains of line segments, with next and previous pointers. Then if you walk off an edge you see if there's another edge to switch to, or if it's NULL then fall. If need be you can wrap up the code to navigate along a series of segments into it's own SurfaceFollower class so it can be easily shared between your player movement and your enemies. Awesome.=) In the meantime I've been checking out Snowman Village and I can see how this approach is versatile. I'm guessing Sega have used something similar in the Sonic games (man, how much I wondered how did they implement those loops), etc. I'll think of something how to calculate these surfaces from tiles, as I want to keep redundancy to a minimum. For my shapes, I just store the vertices in a Ring container, then collision detection connects the dots for itself. But probably, in a game-specific use, the engine can create chains of surfaces from tiles that are adjacent... or dunno.
  7. how to go about platformer physics

    Quote:Original post by OrangyTang ... I've found it much better to explicitly have two different character states - on ground and in air. In the air you do physics-based movement in 2d with forces and gravity, and on the ground you snap to a particular surface and move left/right along it (basically physics along a 1d axis, which may or may not be actually horizontal in the game world). In both states you need to explicitly check every frame to see if you should switch to the other state. So if you're walking you need to see if your surface movement takes you off the edge of the current surface, or if jump has been pressed, at which point you change state and set up your initial velocity for the jump. If you're in the air you need to be checking to see if you've now collided with the ground in which case you change state and snap to the closest point on the surface you've landed on (if your collision is accurate, the snap shouldn't be visually noticable as it'll be precise to within a pixel). ... Thank you so much! I have to say, I felt very lost -- I got to the point of giving the bool isAirborne variable to the entities, but I used it nowhere as consistently as you do (partly because I was a beginner enough to think that realistic physics work=L). I get the 1d breakdown (a vector perpendicular to the collision normal of the platform can be used to determine the 1d axis to walk along), but how do I determine whether the character is off the edge? (collision test collects vertex data and calculates face normal data from it, but these vectors are normalized and there's no way to relate them back to the original vertices) One possible solution that comes to mind is to keep checking against collision with the platform at (character.x, character.y + gravity.y). then, on no collision look for another platform or set the character airborne. it looks a bit crude, or does it? Quote:Original post by OrangyTang In a non-tile based game (like I use, with line segments or polys for surfaces) then you need so way of figuring out "adjacent" surfaces if you walk off the end of one. this will probably be a BSP tree, or storing pointers , or something... any related books out there that you have found useful?
  8. how to go about platformer physics

    after achieving a certain functionality with my game framework, I wanted to test it out writing a very simple 2D jump'n'run. nothing, I repeat nothing unexpected: run, jump, collect stuff, exit through a door. now the framework doesn't restrict you to tile-basedness, it can handle any convex shape with an arbitrary number of sides (collision and display). the game, however, is tile-ised, for simplicity's sake. there isn't really any physics support in the framework (vector reflection with elasticity and friction), and it isn't used at this stage. the collision detection is separating axes theorem based, does swept testing too - it's results are a collision normal and penetration magnitude (for overlap), and a time data for collisions forward within a given timeframe. gravity and friction (the latter is really just a scalar < 1.0f that the entities' x axis velocity gets multiplied by - I'm guessing this isn't the right approach) is applied on every moving object, at every frame. the problems I've encountered are the following: * at times, when walking a row of tiles, a collision with a tile's side is detected (rather than with its top). * the height of jump varies, presumably depending on how deep the character is into the tile thanks to gravity (although it gets moved out of collision when there is no collision -- so I don't understand) I've found a good couple of threads on 2d platformer physics, and some tutorials -- unfortunately they are more or less specific to tile based games. here they are: http://www.gamedev.net/reference/articles/article694.asp http://www.tonypa.pri.ee/tbw/index.html what would be the most accurate and effective approach to gravity, falling, and jumping? if you only calculate gravity and collision with floors while the character is airborne, how do you determine that the character had walked off a ledge? thanks for your input in advance.
  9. xcode linking SDL_Image [SOLVED]

    thank you Jyk, I checked idevgames.com out. it helped in a strangely indirect way ( = it helped!=D): 1, I haven't realized that xcode, for some reason didn't add the frameworks to the copy files build phase. 2, As I was tinkering around the target, I found that it expands to a list of tasks - copy bundle resources, compile sources, link binary, copy frameworks, etc.. Etc equals my previous results: three empty Copy Files Phases. When I tried to add the frameworks, it still didn't work, so I just dragged them from Project (browser) / Linked Frameworks. Hey presto! It works!
  10. xcode linking SDL_Image [SOLVED]

    hi everyone! as I've released a small demo of my c++ project using SDL and SDL_Image, the feedback was that the OSX version had crashed on people. the error message from console: Process: XRhodes [5561] Path: /Users/increpare/Downloads/XRhodes_demo_01_OSX_220808/XRhodes.app/Contents/MacOS/XRhodes Identifier: com.yourcompany.XRhodes Version: ??? (???) Code Type: X86 (Native) Parent Process: launchd [77] Date/Time: 2008-08-26 10:05:51.429 +0100 OS Version: Mac OS X 10.5.4 (9E17) Report Version: 6 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000002, 0x0000000000000000 Crashed Thread: 0 Dyld Error Message: Library not loaded: @executable_path/../Frameworks/SDL_image.framework/Versions/A/SDL_image Referenced from: /Users/increpare/Downloads/XRhodes_demo_01_OSX_220808/XRhodes.app/Contents/MacOS/XRhodes Reason: image not found recent googling has resulted in little information which also didn't seem to help. there were basically two suggestions: - Project / Add New Build Phase / New Copy Files Phase / "Library/Frameworks/SDL_Image.framework" - Project / Edit Project Settings / Linker Settings / Other linker flags / "-framework SDL_Image" I tried both and their combination... No effect. The program keeps running nicely on my computer, and keeps crashing on others' - the same as it w as. Also, in the .app, the SDL_Image framework still doesn't show, only SDL. Questions: * Where can I track the build phases my project has and all that's happening in them? * Where can I find linker output? * What is the solution? [Edited by - trajectorymodifier on August 26, 2008 10:08:19 AM]
  11. object lifetime issues

    thank you for your answer, Rip-off. sorry I opted for a terser version, there is more to the whole code all right: - copy prevention: actually both the SingletonHolder and the subsystems are derived privately from the following class: class NonCopyable { public: NonCopyable() {}; ~NonCopyable() {}; protected: NonCopyable(const NonCopyable& rhs); NonCopyable& operator=(const NonCopyable& rhs); }; - pInst deletion -- I made a mistake in the SingletonHolder code's copy. Here's the original: template <typename T> class SingletonHolder : private NonCopyable { public: // structors static T& Inst() { static std::auto_ptr<T> pInst(new T); return *pInst; } private: // disabled SingletonHolder(); ~SingletonHolder(); }; - as for the other subsystems, you're right -- they don't need to access each other as global. there are the following exceptions: 1, the Log, which every other subsystem does access. 2, the OpenGL based Graphics subsystem has a call for the TextureManager to reload all textures if it was reinitialized. 3, the Input subsys queries the screen size from Graphics The subsystems aren't constructing/destructing each other. The resource managers don't do a thing on creation (not even log), and definitely nothing to do with SDL. other subsystems, in order of declaration and definition (I know, it doesnt necessarily correspond to creation): - Core: //============================================================================== // Core //============================================================================== Core::Core(uint flags) { if(InitSDL_(flags) == false) { LJ::LOG << LOG_FATAL << "Core initialization failed: " << ::SDL_GetError(); LJ::LOG.Record(); } const SDL_version *vLink(::SDL_Linked_Version()); StringT strLink(LJ::GetVersionString(vLink)); LJ::LOG << "Core created (SDL " << strLink << ")."; LJ::LOG.Record(); } Core::~Core() { ::SDL_Quit(); LJ::LOG << "Core is exiting."; LJ::LOG.Record(); } //------------------------------------------------------------------------------ // InitSDL_() // desc: initializes SDL's given subsystems //------------------------------------------------------------------------------ bool Core::InitSDL_(uint flags) { if(::SDL_Init(flags) < 0) { return false; } return true; } // has one more method -- SetCaption() -- could be anywhere else. - AppTimer: constructor logs the fact of construction. also uses SDL_GetTicks(). Destructor logs fact of destruction. - Graphics: constructor logs the fact of the construction. also uses SDL_ShowCursor(). After construction, the client has to initialize it manually (member method) to resolution, color depth and mode (windowed / full screen). This calls the Texturemanager's method to reload all textures (if succesfully initialized). (the Texturemanager is a policy template class specialized for Texture type objects, which has the resource specific functionality, loads a textre file using IMG_LoadImage().) Destructor logs fact of destruction. - Input: constructor logs the fact of construction. uses SDL_WM_GrabInput(). calls for an update, which in turn uses SDL_GetKeyState() and SDL_GetMouseState(). Destructor logs the fact of destruction. - Mixer: logs fact of successful construction, also calling Mix_Linked_Version(). After construction, the client has to initialize it manually (member method) to frequency, number of output and mixing channels, sound format. only uses the Log. Destructor logs the fact of destruction. what's your suggestion to use instead of global objects? is there any way I can prevent multiple instantiation but hard-coding those classes as singletons? where should I put SDL_Init and SDL_Quit? Shall I initialize SDL subsystem by subsystem, delegated to the corresponding subsystems? In the meantime I've revised the code, the Log is also a singleton now - but the problem remains the same, plus from this time on nothing gets logged in the Windows version. The MacOSX version works on as expected (although there's a stupidd time format change in the log after the subsystems get initialized, and I definitely can't put it anywhere...). Also, the application used to work, logged perfectily, could start it more than once in a session -- back before the conditional compiling statements, when AppTimer wasn't a separate class, rather than a part of the game loop, and when the logger was just a global object rather than a singleton. ================================================================================ Sat Jul 12 13:34:51 2008 Logging has started. Sat Jul 12 13:34:52 2008 Core created (SDL v1.2.13). Sat Jul 12 13:34:52 2008 Timer created. Sat Jul 12 13:34:52 2008 Graphics created. Sat Jul 12 13:34:52 2008 Input created. Sat Jul 12 13:34:52 2008 Mixer created (SDL_Mixer v1.2.8). 12/07/2008 13:34:52 opting for video mode: 800x600@0 12/07/2008 13:34:52 SUCCESS: Graphics initialized. video mode is 800x600@32 12/07/2008 13:34:52 SUCCESS: Mixer was successfully initialized. 12/07/2008 13:35:48 Mixer is exiting. 12/07/2008 13:35:48 Input is exiting. 12/07/2008 13:35:48 Graphics is exiting. 12/07/2008 13:35:48 Core is exiting. 12/07/2008 13:35:48 Logging has stopped. [Edited by - trajectorymodifier on July 12, 2008 8:34:40 AM]
  12. object lifetime issues

    originally working with SDL on Mac, I've found a strange anomaly after importing my project to Dev-Cpp under a BootCamp Windows XP. for my game subsystems (that mostly wrap SDL) I use singletonized classes (SingletonHolder<Subsystem>), which sit in a namespace and are identified as references. some relevant code: // singletonholder template <typename T> class SingletonHolder { public: static T& Instance() { static T *pInst = new T; return pInst; } private: SingletonHolder(); SingletonHolder(const SingletonHolder &rhs); SingletonHolder& operator=(const SingletonHolder &rhs); ~SingletonHolder(); }; // core.hpp class Core { public: Core(Uint32 flags = SDL_INIT_EVERYTHING); ~Core(); }; // core.cpp Core::Core(Uint32 flags) { atexit(SDL_Quit); if(::SDL_Init(flags) < 0) { exit(1); } LJ::LOG << "Core was succesfully initialized."; } Core::~Core() { LJ::LOG << "Core is shutting down"; } // framework.hpp namespace LJ { extern class Log LOG; // not a singleton extern class Core &CORE; }; // framework.cpp namespace LJ { Log LOG("system.log"); Core &CORE(SingletonHolder<Core>::Instance()); }; Now, the anomaly is that in the windows version the singletonized classes' destructors are never called (their shutdown isn't logged) - whereas the OSX version works like a charm. This had been like that since forever, and didn't seem to cause much trouble. The more severe problem is that, for a while now, the program will NOT execute twice in the same windows session. It will crash on second execution, so hard, that there's no way to shut it down (after some random time and amount of punching it, it will go away, or will it?), and will likely crash DevCpp. Oh, by the way, the first time this happened was after I've introduced some compilation switches to make it easier to use the same source for Mac and Win, such as: #if defined(__APPLE__) #include "SDL.h" #include "SDL_opengl.h" #include "SDL_image/SDL_image.h" #include "SDL_mixer/SDL_mixer.h" #elif defined(__WIN32__) #include "SDL/SDL.h" #include "SDL/SDL_opengl.h" #include "SDL/SDL_image.h" #include "SDL/SDL_mixer.h" #endif Now this doesn't make sense at all. Or does it? My two cents would be that this has to do with SDL not being shut down properly (so I'm not saying the OSX version is perfect, maybe the OS takes care of whatever is in the background). So first, I've got rid of atexit and called SDL_Quit() from ~Core(), then tried to do without the singletons, but the problem remained the same. As far as I know, other SDL applications (say, G++ ones rather than VC++) don't have this sort of problem. Does anybody know what's causing this? Actually, as I'm writing this, I get the idea that the windows version might be shutting LJ::LOG down early, then, when the other subsystems' destructor want to call it, it's not there, they crash, and SDL_Quit is never called? Could this be it?
  13. SDL_Mixer playback problem (C++)

    thanks Kylotan, fixed it. I guess I should've put the SDL_GetKeyState() version the first place, as it's not only truer to what's in the original code, but clearer too... (in the original I only used e (after polling) to check against an SDL_QUIT) unfortunately, it wasn't the problem.
  14. SDL_Mixer playback problem (C++)

    Got a problem with sample playback in SDL_Mixer. If I want to restart the sample (Mix_Chunk) I'm currently playing, first I have to stop it in a DIFFERENT cycle. If I stop it right before playing it, the program will crash... (OS: OSX 1.5.2; SDL_Mixer version is 1.2.8) code: const int PAN_LEFT(0); const int PAN_RIGHT(254); const int PAN_CENTER(127); struct SampleState { Mix_Chunk *pChunk_; int channel_; int volume_; int panning_; explicit SampleState(Mix_Chunk *p): pChunk_(p), channel_(-1), volume_(MIX_MAX_VOLUME), panning_(PAN_CENTER) {} ~SampleState() {}; bool SetSample(Mix_Chunk *pC) { Stop(); // SampleState doesn't own the chunk, it is only responsible for the channel if(pC == 0) { return false; } pChunk_ = pC; return true; } void SetVolume(int vol) { volume_ = vol; if(channel_ < 0) { return; } volume_ = ::Mix_Volume(channel_, volume_); } void SetPanning(int panning) { panning_ = panning; if(channel_ < 0) { return; } ::Mix_SetPanning(channel_, PAN_RIGHT - panning_, panning); } void Play(int loops = 0, int ticks = -1, int channelPref = -1) { if(channel_ < 0) { channel_ = ::Mix_PlayChannelTimed(channelPref, pChunk_, loops, ticks); SetVolume(volume_); SetPanning(panning_); } } void Stop() { if(channel_ < 0) { return; } ::Mix_HaltChannel(channel_); channel_ = -1; } }; // initial setup, skipped Mix_Chunk *pMyChunk(::Mix_LoadWAV("test.wav")); SampleState myState(pMyChunk); SDL_Event e; bool done(false); bool toProcess; while(!done) { toProcess = ::SDL_PollEvent(&e); Uint8 *kStates(::SDL_GetKeyState(0)); if(toProcess) { switch(e.type) { case SDL_QUIT: done = true; break; } } if(kStates[SDLK_SPACE] == 1) { /* crash code (if placed here): //myState.Stop(); */ myState.Play(); } // non-crash code: else { myState.Stop(); } } So: - when I place something that calls ::Mix_HaltChannel() in front of ::Mix_PlayChannel(), it will crash the program. - if I place it so as the two doesn't get executed in the same cycle, they're OK (I guess it's sort of a timing issue, but not being multithread(head)ed, I can't afford waiting in the performance-intensive part of the program for a comfortability feature (I used to call Stop() from within Play()). - and I can't Play() the sample again if I don't Stop(), as the channel won't be reset. I know I could do this by using a call-back function (with ::Mix_ChannelFinished), but I have no way to correspond the call-back function's signature (void (*cbfunc)(int /*channelID*/)) to my SampleStates. (attempts included storing channels in my Mixer class (basically an initializer for the SDL_Mixer) and giving SampleState a static member std::vector <SampleState*> for each channel) - if I remove the channel check in Play() I lose track of the channel and soon run out of channels -> crash. do I have a completely wrong grasp on SDL_Mixer with this SampleState model? does it make sense at all to write a C++ 'wrapper' around SDL_Mixer? [Edited by - trajectorymodifier on June 23, 2008 8:00:40 AM]
  15. Hey everyone, could anybody help me out? whenever I try to compile my code, VC coughs up the above mentioned error. wait. I've googled for it, seen the related msdn and gamedev.net topics, but whatever I've found and tried wasn't helpful. so, the exact setup is a VC++ 2005 Express v8.0 with SDL 1.2.12 (manually compiled) and OpenGL. // texturemanager.h #include "sdl/sdl.h" #include "sdl/sdl_opengl.h" #include "gl/glu.h" #include &lt;string&gt; struct Texture { GLuint glID; std::string filename; GLfloat width; GLfloat height; }; typedef std::map&lt;Uint32, Texture&gt; TextureContainer; class TextureManager { protected: // data members TextureContainer textures_; public: // constructor TextureManager(); }; // texturemanager.cpp TextureManager::TextureManager() { textures_.clear(); } - project settings \ code generation \ runtime library is Multithreaded DLL, as required by SDL. (tried to change it, but of course, that didn't work) - solution config is Debug (someone suggested changing it to Release to see if the error goes away -- no, and some more errors come along for about every SDL and OpenGL function call. does anybody know why the hell is THAT?) - tried without the typedef. (and btw, I could (success)fully compile a simple SDL+OpenGL demo, which didn't use of std::map, so it's really not the problem.) - EDIT: almost forgot, I've tried to change the project settings \ general \ character set from Unicode (which it originally was), but that didn't help either every bit of help is appreciated - thanks! [Edited by - trajectorymodifier on October 12, 2007 7:59:49 PM]
  • Advertisement