小编mja*_*mes的帖子

基本游戏结构问题

我正在构建一个简单的2D游戏,我想知道是否有一些比我更好的编码器可以建议一个设计其基本架构的好方法.

游戏非常简单.屏幕上有许多类型的单元可以进行拍摄,移动和执行命中检测.屏幕放大和缩小,屏幕侧面有一个菜单UI栏.

我现在的架构看起来像这样:

Load a "stage".
Load a UI.
Have the stage and UI pass references to each other.
Load a camera, feed it the "stage" as a parameter. Display on screen what the camera is told to "see"

Main Loop {
if (gameIsActive){
   stage.update()
   ui.update()
   camera.updateAndRedraw()
   }
}else{
   if (!ui.pauseGame()){
       gameIsActive=true
   }

if(ui.pauseGame()){
   gameIsActive=false
}


stage update(){
Go through a list of objects on stage, perform collision detection and "action" checks.
objects on stage are all subclasses of an …
Run Code Online (Sandbox Code Playgroud)

architecture

2
推荐指数
1
解决办法
483
查看次数

C++模板化返回

我有一个基于"实体"的程序,它包含"组件"(组成FTW).

组件可能包括许多不同的类型,包括脚本,资产等.我想构建一个名为Entity的函数

实体具有字符串映射和实际组件,以便可以按类型名称搜索组件.

我想要一个叫做的函数

<Component T>GetComponent(char* TypeName, <T>);
Run Code Online (Sandbox Code Playgroud)

其中包含字符串和类型名称,并返回所请求的类型化组件.

用C++模板做这样的事情有可能吗?以上显然不起作用,我不知道如何去做.

谢谢

编辑:

我不是在找工厂.

实体保存不同类型组件的实例.目前这已经完成了

std::vector<Component> componentList; 
Run Code Online (Sandbox Code Playgroud)

std::vector<char*> componentNames; 
Run Code Online (Sandbox Code Playgroud)

谁的索引保证是相同的.我可能稍后会写一张合适的地图.

我只是希望GetComponent返回一个正确类型的引用,该引用指向ComponentList中Entity持有的类型名称的已定时组件.

c++ architecture templates composition

2
推荐指数
1
解决办法
879
查看次数

如何处理在C++中的类之间传递运行时大小的数组

现在我有一个简单的类来处理将XML文件解析为对我有用的int.看起来像这样:

int* DataParser::getInts(){
    *objectNumbers = new int[getSize()];
    for (int i=0;i<getSize();i++){
            objectNumbers[i]=activeNode->GetNextChild()->GetContent();
    }
    return objectNumbers;
 }
Run Code Online (Sandbox Code Playgroud)

在该计划的主要部分,我通过以下方式收到:

int* numbers= data->getInts();
///Do things to numbers[]
delete numbers;
Run Code Online (Sandbox Code Playgroud)

一切正常,直到删除命令,崩溃一切.这样做的正确方法是什么?

c++ memory arrays

1
推荐指数
1
解决办法
309
查看次数

救命!当喂食strtok结果时,strcmp对我说谎

strcmp,当喂到strtok的结果时,在下面的代码中似乎是公然对我撒谎.

int fSize;
char * buffer=NULL;
char * jobToken = "job";
char * nextToken=NULL;
job * curJob=NULL;
struct node * head=NULL;
struct node * parseList(FILE* file){
    fseek(file,0,SEEK_END);
    fSize=ftell(file);
    buffer = (char*)malloc(fSize+1);
    printf("%d chars: reading buffer now:\n",fSize);
    fseek(file,0,SEEK_SET);
    fread (buffer,1,fSize,file);
    nextToken = strtok(buffer, " \n");
    while (nextToken!=NULL){
            printf("**Running  Token: %s**\n",nextToken);
            if (strcmp(nextToken,jobToken)){
                    printf("Accepted %s  as %s\n",nextToken,jobToken);                
            }else{
                    printf("not %s, %s\n",jobToken,nextToken);
            }

            printf("End of state - %s\n",nextToken);

            nextToken = strtok(NULL, " \n");
    }
    free (buffer);
    return NULL;
}
Run Code Online (Sandbox Code Playgroud)

将此输入放在parseList参数的文件中:

job 23
job …
Run Code Online (Sandbox Code Playgroud)

c string strtok strcmp

1
推荐指数
1
解决办法
1567
查看次数

如何从Perl运行并结束script()linux命令?

#!/usr/bin/perl
$sim = "multiq";
`make SCHED=$sim`;
`script > scripter`;
`echo hi`;
print pack("c", 04);
~
Run Code Online (Sandbox Code Playgroud)

调用脚本时,此脚本将挂起.不知道如何让perl脚本继续运行.

linux scripting perl command-line

0
推荐指数
1
解决办法
489
查看次数