Jump to content

  • Log In with Google      Sign In   
  • Create Account

kd7tck

Member Since 26 Aug 2012
Offline Last Active Jan 20 2014 10:26 PM

#5000411 sfml uncompatibility with .mp3, .wav suggest audio format

Posted by kd7tck on 12 November 2012 - 07:22 PM

OGG is a container format like avi is.

Personally I would recomend the following:
Use vorbis for songs, package in ogg container.
Use flac for short sounds and also package it into ogg.
Use Audacity for converting.


#5000089 C++ - Is Goto a Good Practice?

Posted by kd7tck on 11 November 2012 - 07:59 PM

Goto was really meant for use when inlining assembly or linking in outside binaries. I use goto all the time when using assembly, it simplifies loops when otherwise a conditional jump might not be necessary for infinite loops. When doing c++ in a purely OOP world, you should never use goto.


#4999860 [SDL/C++] Asking player for text

Posted by kd7tck on 11 November 2012 - 04:05 AM

Make a tree of all possible combinations, map each tree node to a state. The tree paths are state stransitions triggered by an input event like pressing a key.
You start in a nuetral game state, when you get to the door trigger text enter state. In text_enter state loop around for text. When enter key is pressed tranisition to text check state. In text check state examine the text for equality to pre defined strings, if equality is found then transition to activated state. If equality is not found in text check state then transition back to neutral games state.


Here is a roughed out system done in sfml. Incomplete and buggy, but it should get accross the idea of what I mean.
Examples are in the code, so reverse engineering it shouldn't be too hard. The State_manager.hpp should have the examples for using this system.

state.hpp
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//	you must not claim that you wrote the original software.
//	If you use this software in a product, an acknowledgment
//	in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//	and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_STATE_HPP
#define SFML_STATE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include "Export.hpp"
#include <iostream>
#include <string>
#include <map>

namespace sf
{
class State_Event;
class State_Manager;
////////////////////////////////////////////////////////////
/// \brief The Util State Abstract class.
///
////////////////////////////////////////////////////////////
class SFML_UTIL_API State
{
public :
	////////////////////////////////////////////////////////////
	/// \brief constructor
	///
	/// \param string name
	///
	////////////////////////////////////////////////////////////
	State(std::string name);
	////////////////////////////////////////////////////////////
	/// \brief destructor
	///
	////////////////////////////////////////////////////////////
	virtual ~State(){
		if(manager != 0)
			manager->unRegisterState(this);
		if(registered_events.size() > 0){
			it = registered_events.begin();
			(*it)->unRegisterState(this);
		}
	}


	//Virtual functions for assigning user desired functionality
	////////////////////////////////////////////////////////////
	/// \brief second thing to be called every game cycle
	///
	/// \param double current time in milliseconds
	///
	/// \return 0 if successfull
	////////////////////////////////////////////////////////////
	virtual int Update (const double time) = 0;
	////////////////////////////////////////////////////////////
	/// \brief first thing to be called every game cycle
	///
	/// \return 0 if successfull
	////////////////////////////////////////////////////////////
	virtual int Events () = 0;
	////////////////////////////////////////////////////////////
	/// \brief third thing to be called every game cycle
	///
	/// \param Image, canvas to draw on
	///
	/// \return 0 if successfull
	////////////////////////////////////////////////////////////
	virtual int Draw (Image& canvas) = 0;
	////////////////////////////////////////////////////////////
	/// \brief called once when state is done
	///
	/// \return 0 if successfull
	////////////////////////////////////////////////////////////
	virtual int CleanUp () = 0;
	////////////////////////////////////////////////////////////
	/// \brief called once when state is entered
	///
	/// \return 0 if successfull
	////////////////////////////////////////////////////////////
	virtual int Init () = 0;




	////////////////////////////////////////////////////////////
	/// \brief an event was triggered
	///
	/// \param int ID of event
	///
	/// \return bool true on success
	////////////////////////////////////////////////////////////
	bool trigger(int event_id);
	////////////////////////////////////////////////////////////
	/// \brief change state name
	///
	/// \param string new name
	///
	/// \return true if successful
	////////////////////////////////////////////////////////////
	bool setName(std::string name);
	////////////////////////////////////////////////////////////
	/// \brief get state name
	///
	/// \return string name
	////////////////////////////////////////////////////////////
	std::string getName();
	////////////////////////////////////////////////////////////
	/// \brief get next state name
	///
	/// \return string name, "" if none
	////////////////////////////////////////////////////////////
	std::string nextState();
	////////////////////////////////////////////////////////////
	/// \brief change DefaultNextStateName
	///
	/// \param string new name
	///
	/// \return true if successful
	////////////////////////////////////////////////////////////
	bool setDefaultNextStateName(std::string name);
	////////////////////////////////////////////////////////////
	/// \brief check if state is done, then transition to next state
	///
	/// \return bool ,this is the triggered variable
	////////////////////////////////////////////////////////////
	bool stateDone();

	////////////////////////////////////////////////////////////
	/// \brief register a state_event with this state
	///
	/// \param State_Event*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void registerEvent(State_Event*);

	////////////////////////////////////////////////////////////
	/// \brief unregister a state_event from this state
	/// un-registers StateChange and removes event from registered_events
	/// \param State_Event*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void unRegisterEvent(State_Event*);

	////////////////////////////////////////////////////////////
	/// \brief register a state transition from this state node
	///
	/// \param int event id
	///
	/// \param string name of next state
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void registerStateChange(int event_id, std::string next_state_name);

	////////////////////////////////////////////////////////////
	/// \brief unregister a state transition from this state node
	///
	/// \param int event id
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void unRegisterStateChange(int event_id);
	////////////////////////////////////////////////////////////
	/// \brief set a manager for this state
	///
	/// \param State_Manager*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void setStateManager(State_Manager*);
	////////////////////////////////////////////////////////////
	/// \brief Change Active status, active status meaning is this state running?
	///
	/// \param bool, active status true or false, the isActive variable
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void setActiveStatus(bool);
	////////////////////////////////////////////////////////////
	/// \brief Get the Active status, active status meaning is this state running?
	///
	/// \return bool, the isActive variable
	////////////////////////////////////////////////////////////
	bool getActiveStatus();
	////////////////////////////////////////////////////////////
	/// \brief reset the trigger by setting it to false
	////////////////////////////////////////////////////////////
	void resetTrigger();
protected :
	//state identifier
	std::string state_name;
	std::vector <State_Event*> registered_events;
	std::vector <State_Event*>::iterator it;
	//state to state mappings based on event_id
	std::map <int, std::string> eventIdStateTrigger;
	//the next state to run after this state ends
	std::string next_state_name;
	//if next_state_name is no longer valid
	std::string default_next_state_name;
	//if triggered then state manager will transition to next state, can only be triggered if state is active
	bool triggered;
	//if this state is currently cycling with state manager
	bool isActive;
	//pointer to the state_manager for this state
	State_Manager* manager;
};


////////////////////////////////////////////////////////////
/// \brief A NULL State.
///
////////////////////////////////////////////////////////////
class SFML_UTIL_API NULLState : public State
{
public:
	NULLState() : State("")
	{
		;
	}
	~NULLState()
	{
		;
	}
	int Update (const double time)
	{
		return 0;
	}
	int Events ()
	{
		return 0;
	}
	int Draw (Image& canvas)
	{
		return 0;
	}
	int CleanUp ()
	{
		return 0;
	}
	int Init ()
	{
		return 0;
	}
protected:
	;
};
} // namespace sf

#endif // SFML_STATE_HPP

////////////////////////////////////////////////////////////
/// \class sf::State
/// \ingroup util
///
/// sf::State represents a single state within a finite state machine. This is an abstract class.
///
/// Example:
/// \code
///
///class IntroState : public sf::State
///{
///public:
///	std::string name;
///
///	IntroState(std::string n) : sf::State(n)
///	{
///		name = n;
///	}
///
///	~IntroState()
///	{
///		;
///	}
///
///	int Update (const double time)
///	{
///		std::cout << "Intro_Update_" << name << std::endl;
///		return 0;
///	}
///
///	int Events ()
///	{
///		std::cout << "Intro_Events_" << name << std::endl;
///		return 0;
///	}
///
///	int Draw (sf::Image& canvas)
///	{
///		std::cout << "Intro_Draw_" << name << std::endl;
///		return 0;
///	}
///
///	int CleanUp ()
///	{
///		std::cout << "Intro_Cleanup_" << name << std::endl;
///		return 0;
///	}
///
///	int Init ()
///	{
///		std::cout << "Intro_Init_" << name << std::endl;
///		return 0;
///	}
///};
///
/// \endcode
///
/// \see sf::State
///
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// \class sf::NULLState
/// \ingroup util
///
/// sf::NULLState represents a single state within no real functionality.
///
/// Example:
/// \code
///
/// \endcode
///
/// \see sf::NULLState
///
////////////////////////////////////////////////////////////






state_event.hpp
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//	you must not claim that you wrote the original software.
//	If you use this software in a product, an acknowledgment
//	in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//	and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_STATE_EVENT_HPP
#define SFML_STATE_EVENT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "Export.hpp"
#include <iostream>
#include <string>
#include <vector>

namespace sf
{
class State;
////////////////////////////////////////////////////////////
/// \brief The Util State_Event class.
///
////////////////////////////////////////////////////////////
class SFML_UTIL_API State_Event
{
public :
	////////////////////////////////////////////////////////////
	/// \brief constructor
	///
	/// \param int id
	///
	////////////////////////////////////////////////////////////
	State_Event(int id);

	////////////////////////////////////////////////////////////
	/// \brief destructor
	///
	////////////////////////////////////////////////////////////
	~State_Event();

	////////////////////////////////////////////////////////////
	/// \brief trigger this event, and trigger all registered states
	///
	/// \return bool true on success
	////////////////////////////////////////////////////////////
	bool trigger();

	////////////////////////////////////////////////////////////
	/// \brief obtain this event's ID
	///
	/// \return int Event ID
	////////////////////////////////////////////////////////////
	int getId();
	////////////////////////////////////////////////////////////
	/// \brief change this event's ID
	///
	/// \param int id
	///
	////////////////////////////////////////////////////////////
	void setId(int id);

	////////////////////////////////////////////////////////////
	/// \brief register a state with this event
	///
	/// \param State*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void registerState(State*);

	////////////////////////////////////////////////////////////
	/// \brief unregister a state from this event
	///
	/// \param State*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void unRegisterState(State*);
protected :
	int event_id;
	static std::vector<State*> registered_states;
	std::vector<State*>::iterator it;
};
} // namespace sf

#endif // SFML_STATE_EVENT_HPP

////////////////////////////////////////////////////////////
/// \class sf::State_Event
/// \ingroup util
///
/// sf::State_Event represents an event that can register with multiple states.
///
/// Example:
/// \code
/// //create new state_event and register it to a State
/// sf::State_Event* enter_key_press_event = new sf::State_Event(0);
/// state_pntr->registerEvent(enter_key_press_event);
///
/// //map event to other state
/// state_pntr->registerStateChange(enter_key_press_event->getId(), state_pntr_2->getName());
///
/// //trigger an event, activates the mapping made earlier
/// enter_key_press_event->trigger();
/// \endcode
///
/// \see sf::State_Event
///
////////////////////////////////////////////////////////////







state_manager.hpp
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//	you must not claim that you wrote the original software.
//	If you use this software in a product, an acknowledgment
//	in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//	and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_STATE_MANAGER_HPP
#define SFML_STATE_MANAGER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "Export.hpp"
#include <iostream>
#include <string>
#include <map>
#include <vector>

namespace sf
{

class State;
class Image;
class Clock;
class Time;
class NULLState;
////////////////////////////////////////////////////////////
/// \brief The Util State_Manager class.
///
////////////////////////////////////////////////////////////
class SFML_UTIL_API State_Manager
{
public :
	////////////////////////////////////////////////////////////
	/// \brief constructor
	///
	////////////////////////////////////////////////////////////
	State_Manager();
	////////////////////////////////////////////////////////////
	/// \brief destructor
	///
	////////////////////////////////////////////////////////////
	~State_Manager();
	////////////////////////////////////////////////////////////
	/// \brief register a state with this state manager
	///
	/// \param State*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void registerState(State*);
	////////////////////////////////////////////////////////////
	/// \brief unregister a state with this state manager
	///
	/// \param State*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void unRegisterState(State*);
	////////////////////////////////////////////////////////////
	/// \brief cycle one itteration, checks all states and runs them for one pass
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void Cycle();
	////////////////////////////////////////////////////////////
	/// \brief ends state machine, and cleans everyhting up
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void Halt();
	////////////////////////////////////////////////////////////
	/// \brief set current state
	///
	/// \param State*
	///
	/// \return void
	////////////////////////////////////////////////////////////
	void setCurrentState(State*);

	////////////////////////////////////////////////////////////
	/// \brief get current state
	///
	/// \return State*
	////////////////////////////////////////////////////////////
	State* getCurrentState();

protected :
	std::vector<State*> states;
	std::string currentState;
	std::string nextState;
	std::string previousState;
	std::vector<State*>::iterator it;
	State* baseState;
	Image* backBuffer;
	Clock* clock;
	Time* time;
};
} // namespace sf

#endif // SFML_STATE_MANAGER_HPP

////////////////////////////////////////////////////////////
/// \class sf::State_Manager
/// \ingroup util
///
/// sf::State_Manager manages a collection of states
///
/// Example:
/// \code
///
///class IntroState : public sf::State
///{
///public:
///	std::string name;
///
///	IntroState(std::string n) : sf::State(n)
///	{
///		name = n;
///	}
///
///	~IntroState()
///	{
///		;
///	}
///
///	int Update (const double time)
///	{
///		std::cout << "Intro_Update_" << name << std::endl;
///		return 0;
///	}
///
///	int Events ()
///	{
///		std::cout << "Intro_Events_" << name << std::endl;
///		return 0;
///	}
///
///	int Draw (sf::Image& canvas)
///	{
///		std::cout << "Intro_Draw_" << name << std::endl;
///		return 0;
///	}
///
///	int CleanUp ()
///	{
///		std::cout << "Intro_Cleanup_" << name << std::endl;
///		return 0;
///	}
///
///	int Init ()
///	{
///		std::cout << "Intro_Init_" << name << std::endl;
///		return 0;
///	}
///};
///
///
///
///int main() {
///
///	sf::State* sp;
///	sf::State* sp2;
///
///
///	//create two new classes from abstract type State
///	IntroState *sptr = new IntroState("Intro");
///	IntroState *nsptr = new IntroState("Level1");
///
///
///	//create event trigger
///	sf::State_Event* enter_key_press_event = new sf::State_Event(0);
///
///
///	//access Parent attributes by using State pointer
///	sp = sptr;
///	sp2 = nsptr;
///
///	sp->registerEvent(enter_key_press_event);
///	sp->registerStateChange(enter_key_press_event->getId(), sp2->getName());
///
///	//assign states to state manager
///	sf::State_Manager* sm = new sf::State_Manager();
///	sm->registerState(sp);
///	sm->registerState(sp2);
///	sm->setCurrentState(sp);
///
///
///	while(true)
///	{
///	 //detect action for trigger
///	 if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
///	 {
///	  enter_key_press_event->trigger();
///	 }
///
///	 sm->Cycle();//state cycle
///
///
///	 //exit game loop
///	 if(sm->getCurrentState()->getName() == nsptr->getName())
///	 {
///	  sm->Halt();
///	  break;
///	 }
///	}
///
///	//clean up
///	sptr->unRegisterEvent(enter_key_press_event);
///	enter_key_press_event->unRegisterState(sptr);
///	delete enter_key_press_event;
///	delete sptr;
///	delete nsptr;
///	delete sm;
///	return 0;
///}
///
/// \endcode
///
/// \see sf::State_Manager
///
////////////////////////////////////////////////////////////



#4999817 [SDL/C++] Asking player for text

Posted by kd7tck on 10 November 2012 - 11:05 PM

Just use a state machine. Certain keys will shift what state you are in for example:

say the message is abc, you would start in a nuetral state. If in nuetral state if 'a' is pressed you enter A state. If in A state if 'b' is pressed you enter B state... and so on.


#4999071 Windows .DLL vs Linux .lib.so

Posted by kd7tck on 08 November 2012 - 06:03 PM

GOOGLE!


#4999046 [LIBGDX] Using the LZMA decompress class

Posted by kd7tck on 08 November 2012 - 04:16 PM

Use libphysfs, that will automate this task for you.

edit...
Just found out this was for java.

Why would you need an example for such a simple interface. You have input stream and output stream, thats it.
Once you figure out how streams can be opened and closed this should be a simple matter of filling in the gaps with common logic.

com.badlogic.gdx.utils.compression.Lzma.decompress(new FileInputStream(),new FileOutputStream());

As far as examples for using it to directly load the unzipped files into memory, you should do research into loading binary files using filestreams.

So here are the steps:
1)decompress files to temp directory
2)load binary data into memory or obtain file pointer for streaming the audio
3)load file pointer or data into audio decoder and play it.


Most of these tasks can be done using common java libs, you don't have to use libgdx for everything.


#4989016 C developper, but newbie gamedev, where should I begin?

Posted by kd7tck on 11 October 2012 - 02:12 AM

[...] I highly recommend using a more developer friendly and stable language such as C#. [...]


Why re-invent the wheel when he could just use the numerous engines and libraries already written in C. By the way C# isn't easier for low level tasks, better off just using C/C++ and wrapping in a high level scripting language.


#4988547 Should you support Linux?

Posted by kd7tck on 09 October 2012 - 06:34 PM

Linux gamers may be fewer in numbers but they sure do fork over more cash. The article below illustrates my point.

http://www.hypable.com/2012/10/03/humble-indie-bundle-6-ends-2-million/


#4984959 So I finished the Game From Scratch Tutorial

Posted by kd7tck on 28 September 2012 - 10:26 PM

Rinse and repeat.

It took me years before I felt comfortable doing things without tutorials.


#4984908 opengl front / back buffer problems? (simple example inside)

Posted by kd7tck on 28 September 2012 - 06:26 PM

I know you probably don't want to hear this, but using a Grammar L-system will be more robust. Not only that but most fractals can be generated this way more easily.


#4984903 Will teach c++ to beginners

Posted by kd7tck on 28 September 2012 - 06:10 PM

I'm not an expert, but I will always offer my knowledge free of charge. This belongs in the classifieds, no advertising in the beginners area please.


#4984844 Easy way to add brightness and contrast to a game?

Posted by kd7tck on 28 September 2012 - 02:08 PM

You are better off changing each systems monitor settings, or adding pixel shaders into the games pipeline to do this.


#4984561 Pathfinding, and pixelmovement

Posted by kd7tck on 27 September 2012 - 08:05 PM

Pixel pathfinding is slow, just break everything up into blocks. 4X4 sounds good, then use a grid pathfinding algorithm. The movements can be smothed using a curve fitting algorithm.
Link to translated tutorial


#4984549 C++ Lua and sqlite3 question

Posted by kd7tck on 27 September 2012 - 06:51 PM

Sqlite is for long term storage, if you need it later on then just querry it. Keep in mind that querry processes can be slow, minimize the number you do per game loop.


#4984214 A conversion prgram

Posted by kd7tck on 26 September 2012 - 09:11 PM

Break the string into a series chars, C_str should do fine. Then cast every character to an unsigned int.




PARTNERS