apa*_*dit 2 c++ opengl directx graphics sdl
我想用C++"模仿"一款流行的Flash游戏Chrontron,需要一些帮助才能入门.(注意:不是为了发布,只是为自己练习)
Basics: Player has a time machine. On each iteration of using the time machine, a parallel state is created, co-existing with a previous state. One of the states must complete all the objectives of the level before ending the stage. In addition, all the stages must be able to end the stage normally, without causing a state paradox (wherein they should have been able to finish the stage normally but, due to the interactions of another state, were not).
所以,这种解释了游戏的运作方式.你应该玩一点来真正理解我的问题是什么.
我想解决这个问题的一个好方法是使用链表来存储每个状态,这可能是基于时间的哈希映射,也可能是基于时间迭代的链表.我还是不确定.
实际问题:
现在我有一些粗略的规范,我需要一些帮助来决定使用哪种数据结构,以及为什么.另外,我想知道应该使用哪些Graphics API/Layer来执行此操作:SDL,OpenGL或DirectX(我目前的选择是SDL).我将如何实现并行状态?使用并行线程?
编辑(澄清更多):
操作系统 - Windows(因为这是一个爱好项目,可能会在以后的Linux中执行此操作)
图形 - 2D语言 - C++(必须是C++ - 这是下学期课程的练习)
Q-Unanswered:SDL:OpenGL:Direct X
Q-Answered:避免并行处理
Q-Answered:使用STL实现时间步骤操作.
So far from what people have said, I should: 1. Use STL to store actions. 2. Iterate through actions based on time-step. 3. Forget parallel processing -- period. (But I'd still like some pointers as to how it could be used and in what cases it should be used, since this is for practice).
回答这个问题,我之前大多使用过C#,PHP和Java,所以我不会把自己描述为一个热门的程序员.哪些C++特定知识有助于使我的项目更容易?(即矢量?)
你应该做的是首先阅读并理解"固定的时间步长"游戏循环(这是一个很好的解释:http://www.gaffer.org/game-physics/fix-your-timestep).
然后你要做的是保留一组帧计数器和动作对列表.STL示例:
std::list<std::list<std::pair<unsigned long, Action> > > state;
Run Code Online (Sandbox Code Playgroud)
或者可能是对列表的向量.要创建状态,对于每个操作(玩家互动),您存储帧编号和执行的操作,如果操作只是"按下<X>按下"或"键<X>发布,则很可能获得最佳结果":
state.back().push_back(std::make_pair(currentFrame, VK_LEFT | KEY_PRESSED));
Run Code Online (Sandbox Code Playgroud)
要回放先前的状态,每次玩家激活时间机器时都必须重置帧计数器,然后遍历每个先前状态的状态列表并查看是否与当前帧匹配.如果有,请执行该状态的操作.要优化,可以将迭代器列表保存到每个先前状态列表中的位置.这是一些伪代码:
typedef std::list<std::pair<unsigned long, Action> > StateList;
std::list<StateList::iterator> stateIteratorList;
//
foreach(it in stateIteratorList)
{
if(it->first == currentFrame)
{
performAction(it->second);
++it;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望你明白这个想法......
单独的线程会使事情变得非常复杂,这样每次都会得到相同的结果,这是你无法保证使用单独的线程(无法真正看到如何实现)或非固定的时间步骤游戏循环.
说到图形API,我会选择SDL,因为这可能是让你入门的最简单方法.如果你想要3D,你可以随后从SDL使用OpenGL.
| 归档时间: |
|
| 查看次数: |
2733 次 |
| 最近记录: |