Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


sunk

Member Since 02 Oct 2011
Offline Last Active Feb 16 2015 04:29 PM

Posts I've Made

In Topic: How to correctly inject and share an object to multiple other objects

12 February 2015 - 06:09 PM

Thanks ChaosEngine! Some of the points you made, I had thought about as well but I wasn't too sure since c++ is pretty new to me. I think I'm much more confident with ownership and thinking about how to setup my dependencies. 

 

 


Don't form your opinions based solely on what you read from the internet.

 

Well I guess it pays to have some critical thinking, that's why I posted those links so that someone could help me understand things much easier, Thanks!


In Topic: How to correctly inject and share an object to multiple other objects

12 February 2015 - 03:25 PM


Who owns the A? What is it's lifetime?

 

A is should live through whilst the program is running, like for example a box2d b2World object.

 

 


So B and C just need a reference (possibly const, depending on whether they will modify the A)

 

Aren't storing references a bad idea? http://stackoverflow.com/questions/892133/should-i-prefer-pointers-or-references-in-member-data . Again I'm only going by what I'm reading online.

 

 

 


Note that it's perfectly legitimate to store a raw pointer here to represent the concept of "NO ownership."

 

I like this approach, even though raw pointers are usually not good. I think if someone was to read my code and saw it, it would clearly convey there is no Ownership of this b2World object. If I take this approach, it would mean that I don't need to delete my a object in the destructor of both B and C. It would need to be handled separately?  Something like this then:

main(){
A aObject;
B bObject(&aObject);
C cObject(&aObject);
}

Then A would be deleted when it goes out of scope along with B and C automatically.


In Topic: Looking for a good way to make games in C/C++ on linux for cross-platform

23 January 2015 - 11:43 AM

I'm currently using C++ on my linux machine (ubuntu 14.10). Here's my setup:

 

Eclipse CDT (latest version)

Opengl

SFML

Box2d

Luascript

Terminal

 

SFML and Box2d both can be compiled very easily. I find eclipse the best ide for C++ on linux, it has luascript plugins as well which makes life much easier. Everything should be straight forward to setup.


In Topic: SFML pushGLStates/popGLStates causing opengl texture to disappear

03 January 2015 - 03:40 PM

hi,

 

I'm rather new to SFML, but as I'm not sure of what the RenderWindow::clear() function does, I would rather use glClear(COLOR_BUFFER_BIT) in your Game::render() function.

Or maybe put the RenderWindow::pushGLStates() before the RenderWindow::clear() ?

 

Hope it helps. wink.png

 

I got rid of the RenderWindow::clear(), but that didn't do anything. Infact, I got rid of the pushGLStates/popGLStates and I'm trying to handle all the states my self. Though I'm not really confident with that. Here's what I have:

void Game::render() {

	//TODO draw opengl stuff here
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	m_openglTextureRenderer.render();

	//TODO sfml stuff here
	glPushAttrib(GL_CURRENT_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);
	TextureLoader::checkError("glPushAttrib");
   	glPushMatrix();

	m_mainRenderWindow->resetGLStates();
	m_mainRenderWindow->draw(m_cameraSystem);
	m_mainRenderWindow->draw(m_mapLoader);
//	m_mainRenderWindow->draw(m_animationSystem);
	m_mainRenderWindow->draw(m_mouseSplitterSystem);
	m_fixedTimeStepSystem.drawDebug();

	glPopAttrib();
	glPopMatrix();

	m_mainRenderWindow->display();

}

Infact all my code can be found here in this branch: https://github.com/SundeepK/Clone/blob/wip/refactor_level_loading_code/src/Game.cpp . It's not really in a shareable state atm, but all the code is pretty much there. I don't see any opengl errors in my console, but I'll have to do some reading to understand how to save states, any help appreciated. With the code above, the texture is showing correctly, but I'm not really convinced since I'm not too familiar with opengl.


In Topic: Is there a better way for putting game logic in beginContact

11 December 2014 - 04:21 AM

Norman Barrows is right, simplest approach first, and it's in fact what usually works best. But when things start to get complicated you need a way of managing things a little better. Heres what I'm currently working on doing. I implement my game logic related to collisions in lua script and bind the box2d to lua through lua bind. Taking this approach, each level will have its own lua script (where you can reuse existing scripts if need be) where collisions will be handled, but only collisions that are very specific to that level. E.g. a player jumps on a switch which opens a specific trap door.

 

You can inialiaze your game objects (might be box2d bodies) at the start of a level to the lua script via meta tables and keep a reference to them. Then on a collision, call the a lua function from your c++ and  check if the fixtures/body is the one your interested in and some game logic. I havnt quite finished yet, but I'm at the point where I can implement the game logic via my lua script (my source is on git, I'll update the question when I'm done). I'm taking this approach since im still prototying my ideas and I think it's worth it to spend a little time to experiment, but its hacky since I don't know if it will end up being clean or not and I havnt refactored code yet.


PARTNERS