我有cocos2d的问题.我做了一个接受触摸的课程.类的子类CCLayer和init看起来像这样:
- (id)initWithFrame:(CGRect)frameSize
{
self = [super init];
if (self)
{
frame = frameSize;
size = frame.size;
origin = frame.origin;
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
所以一切都很简单.frame,size并且origin是类变量,但这现在无关紧要.所以我注册了我的班级女巫touchDispatcher,让我可以处理.触摸处理完成如下:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
//Some touch logic which i need.
}
Run Code Online (Sandbox Code Playgroud)
在dealloc我发布所有保留的信息并取消注册touchDispatcher.但从dealloc未被称为.如果我不与注册touchDispatcher的dealloc正确调用.如果重要的话,这个类作为子类添加到另一个CCLayer子类中,并且在该类中dealloc我释放了这个类.
我错过了什么?
我花了整整一天试图编写一些简单的程序,但到目前为止运气很少.我想要做的是编译和运行用nasm汇编编写的程序.
我已升级到最新的nasm(v2.10.09).所以,让我跳到代码中,因为我对这些事情还不太了解.这是一大堆汇编代码,使用elf格式和链接巫婆gcc 在linux上运行(评论是我对正在发生的事情的理解):
bits 32
extern printf
global main
section .data
message db "Hello world!", 10, 0
section .text
main:
pushad ;push all registers on stack
push dword message ;push the string on stack
call printf ;call printf
add esp, 4 ;clear stack
popad ;pop all registers back
ret ;return to whoever called me
Run Code Online (Sandbox Code Playgroud)
没什么太大的.但是我到底该如何让它在OS X上运行呢?我甚至无法以任何方式编译/链接.如果它编译我不能链接它(关于i386和x86无法链接在一起的东西(我明白但是如何修复它?)).我已经尝试了十几种没有运气的方法.
进一步哪能printf和scanf在OS X组件?
这是另一个徒劳的尝试scanf和printf价值回归(这个实际上编译和链接 - 甚至运行!):
[bits 32] ; why the []?
section .data
input_string …Run Code Online (Sandbox Code Playgroud) 我想clone在OS X上使用系统调用.这是一个Unix系统调用,所以它不应该是一个问题,对吧?我已经成功地尝试使用fork,vfork以及其他类似的功能.这是我正在尝试的程序:
#include <sched.h> //Clone resides here
#include <stdlib.h> //standard library
#include <stdio.h>
#include <time.h>
#include <limits.h>
#include <sys/shm.h>
#include <errno.h>
#include <sys/sem.h>
#include <signal.h>
#include <sys/types.h>
int helloWorld();
int main(int argc, char *argv[])
{
int (*functionPointer)() = &helloWorld; //The first argument of clone accepts a pointer to a function which must return int
void **childStack = (void**)malloc(1024); //We will give our child 1kB of stack space
clone(functionPointer, childStack, 0, NULL); //First arugment is …Run Code Online (Sandbox Code Playgroud) 我想组装某种HTTP标头(它只是一个有趣的项目).但我的问题更多是关于如何在C中这样做.我有这样的功能:
void assembleResponse(char **response, const unsigned short code, const unsigned long length, const char *contentType)
{
char *status;
char *server = {"Server: httpdtest\r\n"};
char *content = malloc(17 + strlen(contentType));
char *connection = {"Connection: close"};
printf("AA");
strcpy(content, "Content-type: ");
strcat(content, contentType);
strcat(content, "\r\n");
printf("BB");
switch (code)
{
case 200:
//200 Ok
status = malloc(sizeof(char) * 18);
//snprintf(status, 17, "HTTP/1.1 200 Ok\r\n");
strcpy(status, "HTTP/1.1 200 Ok\r\n");
break;
}
printf("CC");
unsigned int len = 0;
len += strlen(status);
len += strlen(server);
len += …Run Code Online (Sandbox Code Playgroud)